gpt4 book ai didi

jqGrid 自定义格式化程序选项 "unformat"不起作用

转载 作者:行者123 更新时间:2023-12-04 19:47:35 27 4
gpt4 key购买 nike

jqGrid 自定义格式化程序选项“unformat”在提供函数时不起作用。

我正在为此选项提供功能。
custom formatter example
假设工作,但它不工作。

我使用 unformat 函数的主要目的是为排序函数(当您通过单击可排序的列标题进行排序时)提供适当的值,该函数调用提供给 colModel 的 unformat 和格式化程序。

这是我的代码,(所有模块都包含在 jquery UI 和 jqgrid 中。)

<link href="../css/jquery-ui-1.8.11.custom.css" rel="stylesheet" type="text/css"/>
<link href="../css/ui.jqgrid.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../js/jquery-1.5.2.js"></script>
<script type="text/javascript" src="../js/jquery-ui-1.8.11.custom.min.js"></script>
<script type="text/javascript" src="../js/jquery.jqGrid.min.js"></script>


$("#GridTable").jqGrid({
datatype: "local",
colNames: ['id', 'col1', 'col2', 'col3', 'col4'],
colModel: [{name:'id',index:'id', align:'left', width:'260px'},
{name:'col1',index:'col1', width:'170px'},
{name:'col2',index:'col2', width:'160px'},
{name:'col3',index:'col3', sorttype:'float', width:'110px',unformat: unformatterFunction, formatter: formatterFunction },
{name:'col4',index:'col4', sorttype:'float', width:'110px'}
],
altRows: true,
caption: "Test Data",
height: '100%',
autowidth : true,
shrinkToFit: true,
});

function unformatterFunction(cellvalue, options, rowObject){
if(cellvalue=="-"){
return "0";
}
return cellvalue;
}

function formatterFunction(cellvalue, options, rowObject){
if(cellvalue > 15){
return "-";
}
return cellvalue;
}

我花了很多时间来跟踪对 grid.base.js 的调用,发现没有办法去 jquery.fmatter.js 那里为每一行调用 unformatFunction。
我的疑问是 unformatFunction 在排序时没有被调用。

我刚刚通过编辑确认 the example ,它不工作,有些东西是可怕的错误。我想不出任何错误。它根本不调用 colModel 中指定的 unformat 函数。

最佳答案

如果您需要自定义对本地 jqGrid 的排序,则使用自定义 unformatter 是错误的方式。你需要的是使用sorttype作为函数。看the old answer包括演示或this one .

使用 sorttype 的最简单方法因为该函数是从函数返回的转换数据,该数据应该用于定义在相应的比较操作中以定义网格中行的顺序。

关于jqGrid 自定义格式化程序选项 "unformat"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5507171/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com