0

当数据库记录是随机顺序时如何将自动序列号列添加到jqxgrid

数据库中没有记录序列号的特定字段或

如果我们只处理表中的记录子集?

4

2 回答 2

1

将此添加到您的列描述区域

{
 text: 'Srl No', sortable: false, filterable: false, editable: false,
                      groupable: false, draggable: false, resizable: false,
                      datafield: '', columntype: 'number', width: 50,
                      cellsrenderer: function (row, column, value) {
                          return "<div style='margin:4px;'>" + (value + 1) + "</div>";
                      }
},    

然后您的网格代码如下所示

<script type="text/javascript">
        $(document).ready(function () {
            // prepare the data
            var data = MyJsonData;

            var source =
            {
                localdata: data,
                datatype: "json",
                datafields:
                [
                    { name: 'firstname', type: 'string' },
                    { name: 'lastname', type: 'string' }
                ]
            };
            var dataAdapter = new $.jqx.dataAdapter(source);

            $("#jqxgrid").jqxGrid(
            {
                width: 300,
                source: dataAdapter,
                columnsresize: true,
                columns: [
                  {
                      text: 'Srl No', sortable: false, filterable: false, editable: false,
                      groupable: false, draggable: false, resizable: false,
                      datafield: '', columntype: 'number', width: 50,
                      cellsrenderer: function (row, column, value) {
                          return "<div style='margin:4px;'>" + (value + 1) + "</div>";
                      }
                  },
                  { text: 'Name', datafield: 'firstname', width: 125 },
                  { text: 'Last Name', datafield: 'lastname', width: 125 }

                ]
            });
        });
    </script>
于 2014-11-26T08:39:59.990 回答
0

网格单元渲染以及以下代码将有所帮助

{ text: 'Serial Number', dataField: '', columntype: 'number', width: 50,cellsrenderer: slrenderer },

为了渲染我们

var slrenderer = function (value) {
value=value+1; // default numbering starts at 0
return '<div style="text-align: center; margin-top: 5px;">' + value + '</div>';
}
于 2014-05-20T10:00:30.183 回答