jqGrid 自定义格式化程序选项“unformat”不起作用
jqGrid 自定义格式化程序选项“unformat”在提供函数时不起作用。
我正在为此选项提供功能。 自定义格式化程序示例 假设可以工作但它不工作。
我使用 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。
我刚刚通过编辑示例确认它不起作用,出了问题。我想不出有什么错误。它只是不调用 colModel 中指定的 unformat 函数。
jqGrid custom formatter option "unformat" doesnt work when supplied with function.
I am supplying function to this option.
custom formatter example
suppose to work but its not working.
My main purpose of having unformat function is to give proper value to the sort function (when you sort by clicking on the sortable column header) which calls unformat and formatter supplied to the colModel.
Here is my code, (all the modules are included for jquery UI and 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;
}
I have spend lot of hours to trace the call into grid.base.js and found no way that goes to jquery.fmatter.js where the unformatFunction gets called for every row.
My doubt is unformatFunction is not getting called while sorting.
I just confirmed by editing the example, that it is not working, something is horribly wrong. i can't think of any mistakes. its simply dont call the unformat function specified in colModel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要自定义本地 jqGrid 的排序,则使用自定义 unformatter 是错误的方法。您需要的是使用
sorttype
作为函数。查看旧答案,包括演示或这个。使用
sorttype
作为函数的最简单方法是从函数返回转换后的数据,该数据应该用于在相应的比较操作中定义,以定义网格中行的顺序。If you need customize to sorting of the local jqGrid the usage of custom unformatter is the wrong way. What you need is to use
sorttype
as the function. Look at the old answer including the demo or this one.The simplest way to use the
sorttype
as the function is to return from the function converted data which should be used to define in the corresponding compare operation to define the order of the row in the grid.