jqgrid +带空格的数字排序 [英] jqgrid + sorting of number with blanks

查看:208
本文介绍了jqgrid +带空格的数字排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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.

感谢您的帮助.

推荐答案

如果您确实要持有null并将其与0区分,则可以使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆