Dynamic generation of columns and pagination using easyui

Source: Internet
Author: User
<! 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.