<! Doctype HTML> <HTML xmlns = "http://www.w3.org/1999/xhtml">
Showgrid ({}); // The first call // process the returned results, and the data table function showgrid (data) {var Options = {width: "Auto", height: "Auto", rownumbers: True, pagination: True, toolbar: '# toolbar', singleselect: true}; options. columns = eval (data. columns); // convert the returned array string to an object and assign it to the column attribute var DataGrid =$ ("# raingrid") of the DataGrid; DataGrid. dataGrid (options); // generates the DataGrid Based on the configuration options. dataGrid ("loaddata", Data. data [0]. rows); // load data in the local JSON format var P = DataGrid. dataGrid ('getpager'); $ (P ). pagination ({Total: data. data [0]. total, pagenumber: data. data [0]. page, pagesize: 100, // number of records displayed on each page. The default value is 10 pagelist: [100,500,100 0]. // you can set the list of records on each page. beforepagetext: 'dide', // The Chinese Character afterpagetext: 'pages {pages} page' displayed before the page number text box, displaymsg: 'Show {from} to {to} {total} records ', onselectpage: function (pagenumber, pagesize) {$ (this ). pagination ('loading'); $ ('# hid_pagenumber '). val (pagenumber); $ ('# hid_pagesize '). val (pagesize); $ (this ). pagination ('loaded'); query () ;}}); DataGrid. dataGrid ('clearselections ');}}
// Generate jsonpublic string createdatagridcolumnmodel (datatable DT, int total, int pageindex) {stringbuilder columns = new stringbuilder ("{'columns ': [["); int width = 85; foreach (datacolumn Col in DT. columns) {// control the column width. The date width of the first column is 139, and the Chinese character length of the other columns is * 20px if (Col. columnname = "sales") {width = 100;} else {width = 83;} columns. appendformat ("{field: '{0}', Title: '{1}', align: 'center', width: {2 }},", Col. columnname, Col. columnname, width);} If (DT. columns. count> 0) {columns. remove (columns. length-1, 1); // remove unnecessary ','} columns. append ("], data: [{"); columns. append ("\" rows \ ": ["); For (INT I = 0; I <DT. rows. count; I ++) {columns. append ("{"); For (Int J = 0; j <DT. columns. count; j ++) {If (j <DT. columns. count-1) {columns. append ("\" "+ dt. columns [J]. columnname. tostring (). tolower () + "\": "+" \ "" + jsoncharfilter (DT. rows [I] [J]. tostring () + "\", ");} else if (j = DT. columns. count-1) {columns. append ("\" "+ dt. columns [J]. columnname. tostring (). tolower () + "\": "+" \ "" + jsoncharfilter (DT. rows [I] [J]. tostring () + "\" ") ;}} if (I = DT. rows. count-1) {columns. append ("}");} else {columns. append ("},") ;}} columns. append ("]"); columns. append (","); columns. append ("\" Total \ ":"); columns. append (total); columns. append (","); columns. append ("\" Page \ ":"); columns. append (pageindex); columns. append ("}"); columns. append ("]"); columns. append ("}"); Return columns. tostring ();}
Dynamic generation of columns and pagination using easyui