Pager layout can be defined declaratively with pageModel.layout
.
['first','prev', 'next','last', "|", "strPage"]
Localization strings like strPage can be further customized:
strDisplay: "{0} to {1} of {2}", strPage: "Page {0} / {1}"
Page / 0 |
31
2<div id="grid_paging" style="margin:5px auto;"></div>
3
1271
2$(function () {
3var colM = [
4{ title: "Order ID", width: 100, dataIndx: "OrderID" },
5{ title: "Customer Name", width: 130, dataIndx: "CustomerName" },
6{ title: "Product Name", width: 190, dataIndx: "ProductName" },
7{ title: "Unit Price", width: 100, dataIndx: "UnitPrice", align: "right" },
8{ title: "Quantity", width: 100, dataIndx: "Quantity", align: "right" },
9{ title: "Order Date", width: 100, dataIndx: "OrderDate" },
10{ title: "Required Date", width: 100, dataIndx: "RequiredDate" },
11{ title: "Shipped Date", width: 100, dataIndx: "ShippedDate" },
12{ title: "ShipCountry", width: 100, dataIndx: "ShipCountry" },
13{ title: "Freight", width: 100, align: "right", dataIndx: "Freight" },
14{ title: "Shipping Name", width: 120, dataIndx: "ShipName" },
15{ title: "Shipping Address", width: 180, dataIndx: "ShipAddress" },
16{ title: "Shipping City", width: 100, dataIndx: "ShipCity" },
17{ title: "Shipping Region", width: 110, dataIndx: "ShipRegion" },
18{ title: "Shipping Postal Code", width: 130, dataIndx: "ShipPostalCode" }
19];
20var dataModel = {
21location: "remote",
22dataType: "JSON",
23method: "GET",
24url: "/pro/invoice/get"
25//url: "/invoice.php", //for PHP
26}
27var pageModel = {
28type: "local",
29rPP: 20, strRpp: "{0}",
30
31//customize localization strings.
32strDisplay: "{0} to {1} of {2}",
33strPage: "Page {0} / {1}",
34
35layout: ['first','prev', 'next','last', "|", "strPage"]
36}
37var grid1 = $("div#grid_paging").pqGrid({
38width: 900,
39height: 300,
40showTitle: false,
41collapsible: false,
42pageModel: pageModel,
43toolbar: {
44cls: 'pq-toolbar',
45items: [
46{
47type: 'button',
48label: "Custom layout",
49listener: function() {
50//debugger;
51//this.pager().destroy();
52this.option('pageModel.layout',['strDisplay', '|',"strPage", "|", "first","prev","next","last"])
53this.refresh();
54}
55},
56{
57type: 'button',
58label: "Default layout",
59listener: function() {
60//debugger;
61//this.pager().destroy();
62this.option('pageModel.layout',$.paramquery.pqPager.defaults.layout)
63this.refresh();
64}
65},
66{ type: 'separator'},
67{
68type: 'select',
69cls:'rpp',
70label: "Rpp: ",
71value: pageModel.rPP,
72options: [10, 20, 50, 100, 1000],
73listener: function(evt) {
74this.option('pageModel.rPP', $(evt.target).val())
75this.refreshDataAndView();
76}
77},
78{
79type: 'textbox',
80cls: 'curpage',
81label: "Page No: ",
82listener: {
83timeout: function(evt) {
84this.goToPage({page:$(evt.target).val()})
85}
86}
87},
88{ type: 'separator'},
89{
90type: 'button',
91label: "Prev",
92cls:'prev',
93listener: function() {
94var page = this.option('pageModel.curPage');
95this.goToPage({page: page-1})
96}
97},
98{
99type: 'button',
100label: "Next",
101cls:'next',
102listener: function() {
103var page = this.option('pageModel.curPage');
104this.goToPage({page: page+1})
105}
106},
107{
108type: 'button',
109label: "Toggle pager",
110//cls:'next',
111listener: function() {
112this.pager().widget().toggle()
113this.refresh();
114}
115}
116]
117},
118dataModel: dataModel,
119colModel: colM,
120wrap: false, hwrap: false,
121//freezeCols: 2,
122numberCell: { resizable: true, title: "#" },
123title: "Shipping Orders"
124});
125});
126
127
x1
2.pq-toolbar .curpage{
3width:35px;
4}
5
451
2public class Invoice
3{
4[Key]
5public long rowID { get; set; }
6public int OrderID { get; set; }
7public String CustomerName { get; set; }
8public String ProductName { get; set; }
9public Decimal UnitPrice { get; set; }
10public short Quantity { get; set; }
11public DateTime? OrderDate { get; set; }
12public DateTime? RequiredDate { get; set; }
13public Decimal Freight { get; set; }//money
14public String ShipName { get; set; }
15public DateTime? ShippedDate { get; set; }
16public String ShipAddress { get; set; }
17public String ShipCity { get; set; }
18public String ShipRegion { get; set; }
19public String ShipPostalCode { get; set; }
20public String ShipCountry { get; set; }
21}
22public class invoiceController : Controller
23{
24//without paging (load at once)
25public ActionResult get()
26{
27pqTestContext db = new pqTestContext();
28
29//take first 250 records.
30var orders = (from order in db.Invoices
31orderby order.OrderID
32select order).Take(250);
33
34StringBuilder sb = new StringBuilder(@"{""data"":");
35
36JavaScriptSerializer js = new JavaScriptSerializer();
37
38String json = js.Serialize(orders);
39sb.Append(json);
40sb.Append("}");
41
42return this.Content(sb.ToString(), "text/text");
43}
44}
45