Use JqGrid combined with ashx and EF to display list 2 by PAGE

Source: Internet
Author: User
Tags jqgrid

1: CREATE a database TABLE and insert 200000 data records to it: copy the code create table [dbo]. [T_School] ([ID] [int] IDENTITY (255) not null, [SchoolName] [nvarchar] () COLLATE Chinese_PRC_CI_AS NULL, [BuildDate] [datetime] NULL, [Address] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL, [IsSenior] [bit] NULL, [StudentNum] [int] NULL, CONSTRAINT [PK_T_School] primary key clustered ([ID] ASC) WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY] Copy Code 2: myJqgrid. jqGird code encapsulated by js: Copy code/** it is better to display 20 columns by default * List ID = "gridTable" list url = 'handler. ashx? Action = page 'list datatype = 'json' list colNames = ['id', "name", 'Gender ', 'cell phone', 'mailbox '] list colModel =... List title caption = "User List" list modification URL editurl = "Handler. ashx? Action = cursor "sortname =" ID "by default in the list; Page ID gridPagerID =" gridPager "* // The last selected row var lastsel; function myJqGrid (id, url, datatype, colNames, colModel, caption, editurl, sortname, gridPagerID) {var myGrid =$ ("#" + id); myGrid. jqGrid ({url: url, datastr: "data. json ", datatype: datatype, rowNum: 20, rowList: [10, 20, 50], colNames: colNames, colModel: colModel, jsonReader: {repeatitems: false, root: fun Ction (obj) {return obj. rows;}, page: function (obj) {return obj. pageindex;}, total: function (obj) {return obj. pagecount;}, records: function (obj) {return obj. total ;}}, prmNames: {page: 'pageindex', rows: 'pagesize', sort: 'order', Order: 'sort '}, hidegrid: false, rownumbers: true, loadonce: false, sortname: sortname, sortorder: 'desc', pager: "#" + gridPagerID, viewrecords: true, cap Tion: caption, toolbar: [true, "top"], altRows: true, // the last row selected onSelectRow: function (id) {if (id & id! = Lastsel) {grid. jqGrid ('restorerow', lastsel); lastsel = grid. jqGrid ('getrowdata', id) [sortname] ;}}, editurl: editurl});} pay attention to the parameters in the two parts of the Code, pagecount-json indicates the total number of pages, total-json indicates the total number of data rows, and pageindex-json indicates the data of the current page number; prmNames is the name of the paging parameter that is renamed to the backend. The URL uploaded to the backend is GET/CountryHandler. ashx? _ Search = false & nd = 1397394772871 & PageSize = 20 & PageIndex = 1 & Order = ID & Sort = desc copy code jsonReader: {repeatitems: false, root: function (obj) {return obj. rows;}, page: function (obj) {return obj. pageindex;}, total: function (obj) {return obj. pagecount;}, records: function (obj) {return obj. total ;}}, prmNames: {page: 'pageindex', rows: 'pagesize', sort: 'order', Order: 'sort '}, copy code 3: html code and JS Code: Copy the Code

Related Article

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.