jqgrid +带空格的数字排序 [英] jqgrid + sorting of number with blanks
问题描述
我的JQgrid中有一列大小".返回类型是整数.我添加了:
I have a column in my JQgrid which says 'size'. The return type is integer. I have added:
{
name:'sizeKloc',
index:'sizeKloc',
width:60,
editable:false,
sorttype: 'int',
align:'right'
},
在某些情况下,值将作为null
传递.
There are some cases where the value is passed as null
.
我的列具有以下值-0、3、5,null(空白或空格),1,null(空白或空格),null(空白或空格),2、3
My column has following values - 0, 3, 5, null (which is blank or space), 1, null (which is blank or space), null (which is blank or space), 2, 3
但是,当我尝试对ASC进行排序时,应该先在空格后面加上不会发生的实际数字排序.
But when I try to sort ASC, the blanks should be first followed by actual number sorting which doesn't happen.
感谢您的帮助.
推荐答案
If you really want to hold null
and distinguish it from 0 you can use custom sorting instead of usage of sorttype: 'int'
. The usage is very simple. You need just define replacements of the values which can be used for sorting instead of the original values of your data.
以您的情况为例
{name:'sizeKloc',index:'sizeKloc', width:60, editable:false, align:'right'
sorttype: function (cellValue) {
return cellValue === null ? -1000 : Number(cellValue);
}},
或
{name:'sizeKloc',index:'sizeKloc', width:60, editable:false, align:'right'
sorttype: function (cellValue) {
var num = parseInt(cellValue, 10);
return isNaN(num) ? -1000 : num;
}},
确切的代码更多地取决于您使用的数据的格式和类型.
The exact code depend more from the format and type of the data which you use.
这篇关于jqgrid +带空格的数字排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!