jqgrid对不同列上的本地数据进行自定义排序

发布于 2024-10-31 04:14:26 字数 499 浏览 3 评论 0原文

我有一个 jqgrid,其中 dataytype 是本地的。自动排序对于每一列都运行良好。我想知道是否可以根据另一列对不同列进行排序。 为了更好地解释这一点,让我们假设我有三列 OrderNumberAddressPhone 和一个名为 State 的隐藏列。当单击 Address 列时,我实际上想像单击 State 列一样进行排序。

我正在尝试在 onSortCol 事件上执行此操作,我想要类似的内容:

onSortCol: function (index, iCol, sortorder) {

     if(index === "Address"){
         //CHANGE SORTED COLUMN TO STATE AND MAKE THE SORT              
     }
},

I have a jqgrid where dataytype is local. The automatic sort is working fine for each column. I want to know if it's possible to sort a different column based on another column.
To explain this better Lets assume I have three columns OrderNumber, Address, Phone, and a hidden column named State. When the Address column is clicked I actually want to sort like if the State column would have been the one clicked.

I'm trying to do this on the onSortCol event, I want something like:

onSortCol: function (index, iCol, sortorder) {

     if(index === "Address"){
         //CHANGE SORTED COLUMN TO STATE AND MAKE THE SORT              
     }
},

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀中猫帐中妖 2024-11-07 04:14:26

如果您使用远程数据(datatype:'json'datatype:'xml'),您可以非常轻松地实现任何类型的排序。所以我想你的意思是 jqGrid 与你的问题中的本地数据。在这种情况下,我建议您在定义为函数的 colModel 内部使用 sorttype 参数。

您可以为 Address 列定义 sorttype 属性,如下所示:

sorttype: function(cellValue, rowObject) {
    return rowObject.State;
}

或如下所示:

sorttype: function(cellValue, rowObject) {
    return rowObject.State + "_" + cellValue;
}

参数 cellValue 包含将在比较操作中使用的单元格对网格进行排序。 rowObject 是代表具有cellValue 的完整行的对象。从函数 sorttype 返回另一个值作为 cellValue 后,将在比较操作中使用返回的值,而不是 cellValue

sorttype 实现的第一个示例中(参见上文),将根据名称为 State 的列的包含情况,按 Address 列进行排序>。在第二个示例中,具有相同状态的行将另外按地址排序。

您可以在此处查看小型演示。如果单击“税”列,网格将按“id”列排序,其中 id 值将被解释为整数。

If you work with remote data (datatype:'json' or datatype:'xml') you can implement any kind of sorting very easy. So I suppose that you mean jqGrid with local data in your question. In the case I would recommend you to use sorttype parameter inside of colModel defined as function.

You can define for the Address column the sorttype property which looks like the following:

sorttype: function(cellValue, rowObject) {
    return rowObject.State;
}

or like this one:

sorttype: function(cellValue, rowObject) {
    return rowObject.State + "_" + cellValue;
}

The parameter cellValue is the contain of the cell which will be used in compare operation to sort the grid. The rowObject is the opject which reprecent the full row having cellValue. Returnung another value as cellValue from the function sorttype will follow that the returened value will be used in the compare operations instead of the cellValue.

In the first example of sorttype implementation (see above) the sorting by Address column will be done based on the contain of the column with the name State. In the second example, the rows having the same state will be additionaly sorted by address.

You can look on the small demo here. If you click on the "Tax" column the grid will be sorted by "id" column where the id values will be interpret as integer.

墟烟 2024-11-07 04:14:26

如果您正在进行服务器端排序,您只需这样做:

if(sord == "Address"){
    sord = "State";
}

您是否尝试过对客户端排序执行相同的操作:

onSortCol: function (index, iCol, sortorder) {    
    if(index === "Address"){
        index = "State";              
    } 
},

If you were doing server side sorting you would just do this:

if(sord == "Address"){
    sord = "State";
}

Have you tried doing the same for your client side sorting:

onSortCol: function (index, iCol, sortorder) {    
    if(index === "Address"){
        index = "State";              
    } 
},
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文