jqGrid按列名排序索引 [英] jqGrid sort index by column name

查看:400
本文介绍了jqGrid按列名排序索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题.是否有一个功能可以按名称在网格中获取列的当前排序位置?

Simple question. Is there a function to get the current sort position of a column by name in a grid?

推荐答案

remapColumns方法中使用的索引与colModel数组中使用的索引相同.重要的是要理解,索引可以与最初使用的jqGrid的colModel参数不同.如果jqGrid使用选项rownumbers: true,则将在colModel数组的第一位插入名称为'rn'的附加列. colModel数组的所有其他元素的索引将增加.以相同的方式,选项multiselect: true插入列'cb'和选项subGrid: true插入列'subgrid'.以相同的方式,选项treeGrid: truecolModel数组后面附加一些其他隐藏列,这些隐藏列可以由treeReader定义.对于treeGridModel: 'nested',列的默认名称为:'level''lft''rgt''isLeaf''expanded''loaded''icon''level''parent''isLeaf''isLeaf''expanded''loaded''icon'.

The indexes used in the remapColumns method are the same as in the colModel array. It's important to understand, that the indexes can be different as in the colModel parameter of jqGrid used initially. If jqGrid uses options rownumbers: true an additional column with the name 'rn' will be inserted at the first place of colModel array. The indexes of all other elements of colModel array will be incremented. In the same way the option multiselect: true inserts the column 'cb' abd the option subGrid: true inserts the column 'subgrid'. In the same way the option treeGrid: true follows appending colModel array with some additional hidden columns which names can be defined by treeReader. The default names of the columns in case of treeGridModel: 'nested' are: 'level', 'lft', 'rgt', 'isLeaf', 'expanded', 'loaded' and 'icon' or 'level', 'parent', 'isLeaf', 'expanded', 'loaded' and 'icon' in case of treeGridModel: 'adjacency'.

因此,要通过名称查找列的索引,您应该只获取当前的colModel,仔细检查各项,然后找到其中'name'属性是所需列名称的项目.要获取colModel,可以使用$("#grid")[0].p.colModel$("#grid").jqGrid('getgridParam', 'colModel').因此,代码如下所示:

So to find the index of the column by the name you should just get the current colModel, look through the items and find the item where 'name' property are the column name which you need. To get colModel you can use $("#grid")[0].p.colModel or $("#grid").jqGrid('getgridParam', 'colModel'). So the code can be like the following:

var getColumnIndexByName = function (columnName) {
        var cm = $(this).jqGrid('getGridParam', 'colModel'), i, l = cm.length;

        for (i = 0; i < l; i++) {
            if (cm[i].name === columnName) {
                return i; // return the index
            }
        }
        return -1;
    };

和类似的用法

var $grid = $("#grid"),
    iCol = getColumnIndexByName.call($grid[0], 'myColName');

要获取当前已排序列的名称,可以使用$grid.jqGrid('getGridParam', 'sortname')

To get the name of the current sorted column you can use $grid.jqGrid('getGridParam', 'sortname')

这篇关于jqGrid按列名排序索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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