How to configure datagrid and struts2 in easyUI

Source: Internet
Author: User

Datagrid is the most important control of easyUI. Next, let's take a look at what functions it has and how it can be implemented.

$ ('# Firmresult '). datagrid ({singleSelect: true, // you can only select single-choice pagination: true, // display pagination // fit: true, // automatically adapt to the size of the parent container fitColumns: true, // automatically adapt to rownumbers: true for column width, // display the row pageList: [5, 10, 15], // number of records displayed per page pageNumber: 1, // current page pageSize: 10, // current page size height: 300, // height // url: "firmManager. action ", columns: [[// attribute and name settings for each column {field: 'userid', checkbox: true}, {field: 'devid', title: 'device id', formatter: function (value, rowData, rowIndex) {var devId = rowData. userId; return devId ;},{ field: 'snstart', title: 'snstart' },{ field: 'snend', title: 'snend' },{ field: 'registerdate', title: 'registration time'}]});
After the datagrid is initialized, we have to explain how to display the data in the datagrid.

First, let's take a look at how the struts2 configuration is configured. If you want struts to support the josn format, you can use either of the following methods:

1. Directly inherit the json Configuration

2. Set the interceptor in the configuration file.

We use the second method. Of course, necessary jar packages are essential. See the following configuration

 
  
 
         
  
 
 

  Result
  
 

After the configuration is completed, let's take a look at how to display the queried data in the datagrid by page. Some people may see how the results are displayed on the first page. The possible problem is that although you set pagination, you have searched all the records. Of course, there is also a solution. You can use front-end paging. However, we use the back-end page, that is, the number of records displayed on each page is queried and put into the josn object.

// Query function subSerach () {var startDate = $ ("# startDate "). datebox ('getvalue'); var endDate = $ ("# endDate "). datebox ('getvalue'); var firmId = $ ("# firmId "). val (); var userType = $ ("# userType "). combobox ('getvalue'); if (startDate = '') {$. messager. alert ('warning', 'enter the start date. '); $ ("# StartDate "). focus (); return;} if (endDate = '') {$. messager. alert ('warning', 'enter the end date. '); $ ("# EndDate "). focus (); return;} if (startDate> endDate) {$. messager. alert ('warning', 'end date should not be earlier than the start date. '); $ ("# EndDate "). focus (); return;} var grid = $ ('# firmresult'); // The key is the paging key. Here we get some paging attributes, such as the page number and the number of records displayed on each page. var options = grid. datagrid ('getpager '). data ("pagination "). options; var num = options. pageNumber; var size = options. pageSize; var params = {// The parameter here is the query condition that we pass to the background. In the background, we use a query condition object and the paging object 'firmquerybean. startDate ': startDate, 'firmquerybean. endDate ': endDate, 'firmquerybean. firmId ': firmId, 'firmquerybean. usertype': userType, 'pagination. pageNo ': num, 'pagination. pageSize ': size}; $. post ("firmInfoManager. action ", params, // submit the function (data) {if (data & data. reusltList) {var ret = []; var json = data. reusltList; var atotal = data. counts; for (var I = 0; I
 
  
Package com. dbstar. uaas. utils; import java. util. list; public class Pagination {// This is our paging object/*** total number of records */private long counts; /*** page */private Integer pageNo = 1;/*** the number of records displayed on each page. The default value is 10 */private Integer pageSize = 10; /*** total page number */private int pageCount;/*** success/private boolean suc;/*** records displayed on the current page */private List reusltList; public Integer getPageNo () {return pageNo;} public void setPageNo (Integer pageNo) {this. pageNo = pageNo;} public Integer getPageSize () {return pageSize;} public void setPageSize (Integer pageSize) {this. pageSize = pageSize;} public int getPageCount () {return pageCount;} public void setPageCount (int pageCount) {this. pageCount = pageCount;} public ListGetReusltList () {return reusltList;} public void setReusltList (List reusltList) {this. reusltList = reusltList;} public long getCounts () {return counts;} public boolean isSuc () {return suc;} public void setSuc (boolean suc) {this. suc = suc;} public void setCounts (long counts) {if (counts % pageSize = 0) {pageCount = (int) counts/pageSize;} else {pageCount = (int) (counts + pageSize)/pageSize;} if (pageNo <1) {pageNo = 1;} else if (pageNo> pageCount) {pageNo = pageCount;} this. counts = counts ;}}Okay. Let's take a look at the background query method.

/*** Query vendor information * @ return */public String searchFirmInfos () {try {if (firmManager = null) firmManager = new FirmManager (); if (firmQueryBean = null) {firmQueryBean = new FirmQueryBean ();} if (pagination = null) {pagination = new Pagination ();} pagination = firmManager. searchFirmInfosByPage (firmQueryBean, pagination); pagination. setSuc (true);} catch (Exception e) {pagination. setSuc (false); logger. error ("ther operate DB error .. "); e. printStackTrace ();} result = JSONObject. fromObject (pagination); return SUCCESS ;}
Finally, let's take a look at the page showing the effect.

Well, we can make it a success. If you have any questions, we can discuss them together. After all, easyUI is not exposed for a long time.




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.