Java programmer cainiao (11) common functions of extjs4 (3) -- Use of list grid (with integrated query and paging)

Source: Internet
Author: User

During development, the list function in the database table is very commonly used. Generally, the list has the comprehensive query and paging functions. In extjs4, it provides us with a powerful list grid function, record it here as a memo


VaR mystore = ext. create ('ext. data. store', {fields: ['id', 'occurdate', "occurplace", "charger", "content", "inputusername", "institutionname"], // pagesize: 10, proxy: {type: 'ajax ', URL: 'centerbanktrendaction! Centerbanktrendlist ', Reader: {type: 'json', root: 'trendlist', totalproperty: 'Total' }}, autoload: true}) var mygrid = ext. create ('ext. grid. panel ', {tbar: [{xtype: 'button', icon :'.. /images/add.png ', text: 'add dynamic', Handler: function () {win. show () ;}], Title: 'Pedestrian dynamics ', renderto: ext. getbody (), // layout: {type: 'vbox', align: 'left'}, frame: True, store: mystore, columns: [New Ext. grid. rownumberer (), // {// xtype: 'Actioncolumn', // header: "delete", // width: 50, // icon :'.. /images/delete3.png ', // handler: function (grid, rowindex, colindex) {// Ext. messageBox. confirm ("OK", 'Are you sure you want to delete it? ', Function (BTN) {// If ('yes' = BTN) {// var store = mygrid. getstore (); // VaR value = store. getat (rowindex); // var trendid = value. get ('id'); // window. location. href = "centerbanktrendaction! Deletetrend? Trend. id = "+ trendid; //}) //} // handler is closed //}, {xtype: 'actioncolumn', header:" details ", width: 40, icon :'.. /images/edit.png ', Handler: function (grid, rowindex) {var id = grid. getstore (). getat (rowindex ). get ('id'); editwinshow (ID);} // handler is closed}, {header: "time", width: 100, dataindex: 'occurdate ',}, {header: "location", width: 150, dataindex: 'occurplace', // sortable: true}, {header: "dynamic content", width: 160, dataindex: 'content' ,}, {header: "XX", width: 160, dataindex: 'insttiontionname' ,}, {header: "owner", width: 80, dataindex: 'charger ',}], // start dockeditems: [{xtype: 'pagingtoolbar', store: mystore, // same store gridpanel is using Dock: 'bottom ', // pagination location emptymsg: 'No date', displayinfo: True, displaymsg: 'currently displayed {0}-{1} records/{2} records ', beforepagetext: 'ter', afterpagetext: 'page/{0} page in total'}], // page end });

First, create a data source store. Generally, Ajax is used to load the data source. You can check the help documentation for other methods. Store:

The URL specifies where to load the data source,

Reader is a loader,

Type specifies the data type to be loaded. Here I use the JSON data type.

Root specifies the variable name for loading the data source

Totalproperty specifies the variable name for the total number of records

Autoload specifies whether to automatically load


After creating the data source, define a grid. Generally, add a tbar in the grid to control the integrated query.

Store specifies the data source. Here, we specify the mysrore

Renderto specifies which part of the page the grid is rendered

Columns specifies the columns in the grid.

Dataindex specifies the name of the data to be displayed in this column

Dockeditems refers to the content to be displayed in the dock column below, which is the page part displayed

In some actioncolumns, Handler specifies the function to be executed when the row button is clicked.

Here, one thing to note is a comprehensive query. The above example does not provide a comprehensive query, but only provides a simple grid instance. Next I will explain how to implement the comprehensive query here.

Since most of the grid data sources are implemented by loading data via Ajax, If we directly transmit the query parameters to the backend when submitting a comprehensive query, we cannot get the correct results when loading the data source through Ajax. Therefore, we can change our mind to dynamically Add the comprehensive query parameters to the store URL during the architecture store. After adding it to the URL, then let the store load the data source. That is to say, when we click the submit button of the comprehensive query, we load the data source, so that we can call the created store method we defined when the submit button triggers the event. Take a look at the specific example below:

Tbar: [yearscombx, financeinstitutioncombx, // a drop-down list is displayed, which will be dropped to {xtype: 'click', icon :'.. /images/accept.png ', text: 'view', Handler: function () {var year = yearscombx. getvalue () = NULL? 0: yearscombx. getvalue (); var institutionid = financeinstitutioncombx. getvalue (); freshstore (year, institutionid) ;}}], function freshstore (year, institutionid) {If (institutionid = NULL) institutionid = ''; mystore = ext. create ('ext. data. store', {fields: ['reportinstittion ', 'byparameter institution', 'regiondate', 'regioncontent', 'result', 'recordtyear ', 'reportusername'], // pagesize: 10, proxy: {type: 'ajax ', URL: "Your judicialcaseaction! Assistjudiciallist? Search. institutionid = "+ institutionid +" & search. year = "+ year, Reader: {type: 'json', root: 'freezeaccountlist ', totalproperty: 'Total' }}, autoload: true}) mygrid. reconfigure (mystore, CM); mygrid. getdockedcomponent ('pagebar '). BIND (mystore); // rebind the page}

One thing to note here is that a new store will be created each time you submit a comprehensive query, so you should bind the data source to the grid and pagebar at the end.

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.