且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jqGrid动态列

更新时间:2023-12-01 14:25:58

一个人可以使用jqGrid创建许多不同的网格,树形网格,子网格等.了解您要显示10行还是100000行的网格非常重要.如果您有100000行(或其他大量行),则必须实现服务器端分页和数据排序.因此,如果用户单击下一页"按钮,则应该从服务器加载下一行.为什么您需要在分页或排序时发送所有colModel数据?因此,您应该清楚地了解到,在服务器端场景中,只需创建一次网格的所有结构一次,然后只需刷新网格主体即可.因此,一次发送所有信息(列名,列模型,数据等)是个不好的选择.

One can use jqGrid to create many different grids, tree grids, subgrids and so on. It's very important to understand whether you want to display grid with 10 rows or with 100000 rows. If you have 100000 rows (or some other large number of rows) you will have to implement server side paging and sorting of data. So if the user would click on the "next page" button the next rows should be loaded from the server. Why you would need to send all colModel data on paging or sorting? So you should clear understand that in server side scenario one need create all structures of grid only once and then one need refresh only the body of grid. So it would be bad choice to send all information (column name, column model, data,... at once).

仅当网格中有几百或几千行并且可以使用loadonce: true选项时,它们才可以加载一次所有信息(列名,列模型,数据等). .)每个单独的jQuery.ajax调用,然后使用datatype: "local"并使用包含所有网格数据的data参数创建jqGrid.

Only if you have some hundreds or some thousand of rows in the grid and you can use loadonce: true option them you can load once all information (column name, column model, data, ...) per separate jQuery.ajax call and then create jqGrid with datatype: "local" and using data parameter which contains all grid data.

已更新:如果需要更改

// in the example below the grid with id="list" will be created 
// with column having name: "c4" in colModel
var $grid = $("#list"), columnName = "c4";

...

var $colHeader = $("#jqgh_" + $.jgrid.jqID($grid[0].id) + "_" + $.jgrid.jqID(columnName)),
    $sortingIcons = $colHeader.find(">span.s-ico");

// change the text displayed in the column 
$taxHeader.text("New header text");

// append sorting icons to the new text
$taxHeader.append($sortingIcons);