在JQgrid中更改rownumber属性的列位置

时间:2014-09-10 12:54:32

标签: jqgrid

我已启用' rownumber'属性。所以它通过在最左边插入一行来显示行号。所以第一列显示行号。但是我希望在第三列之间显示行号。

有没有办法改变列位置?

1 个答案:

答案 0 :(得分:0)

jqGrid的某些列具有特殊含义,将由jqGrid 创建,具体取决于您使用的选项。它是"rn"rownumbers: true),"cb"multiselect: true)和subgridsubGrid: true)。请参阅示例the line代码。 jqGrid代码的许多部分只是测试选项,然后根据列是 jqGrid中的第一个列的假设使用列的索引。因此理论上可能编写可以将原始 "rn"列移动到另一个位置的代码,但代码将非常棘手且可能很长。例如,查看the answer的演示。

所以我建议你只需将自定义列添加到看起来像"rn"列的网格中,并用相应的数据填充它。列定义可能如下所示

{ name: "myRowNumbern", width:25, sortable: false, resizable: false, hidedlg: true,
    search: false, align: "center", fixed: true,
    classes: "ui-state-default jqgrid-rownum" }

更新:我创建了the demo来演示该方法。相应代码中最重要的部分如下:

$("#list").jqGrid({
    curRowNum: 1, // current row number parameter used in custom formatter
    colModel: [
        ...
        { name: "myRowNumbern", width: 25, sortable: false, resizable: false,
          hidedlg: true, search: false, align: "center", fixed: true,
          classes: "ui-state-default jqgrid-rownum",
          formatter: function () {
              var p = $(this).jqGrid("getGridParam"),
                  rn = p.curRowNum +
                      (parseInt(p.page, 10) - 1)*parseInt(p.rowNum, 10);
              p.curRowNum++;
              return rn.toString();
          } },

        ...
    ],
    loadComplete: function () {
        var p = $(this).jqGrid("getGridParam");
        p.curRowNum = 1; // reset curRowNum
    }
});
相关问题