Easyui DataGrid use (Good)

Source: Internet
Author: User

Load the relevant JS and CSS, because Easyui relies on jquery, all load easyui before loading jquery, otherwise you will not be prompted to find the DataGrid

  1. <!--load jquery--
  2. <script type="Text/javascript" src="Plugins/jquery/jquery-1.4.2.min.js"> </Script>
  3. <!--load Jquery-easyui --
  4. <link rel="stylesheet" type= "text/css" href= "plugins/jquery/ Jquery-easyui-1.1.2/themes/default/easyui.css ">
  5. <link rel="stylesheet" type= "text/css" href= "plugins/jquery/ Jquery-easyui-1.1.2/themes/icon.css ">
  6. <script type="Text/javascript" src= "plugins/jquery/jquery-easyui-1.1.2/ Jquery.easyui.min.js "></script>

Interface Join

    1. <table id="Cxdm"></table>

Load the DataGrid's JS code

  1. Page load
  2. $ (document). Ready (function () {
  3. Loadgrid ();
  4. });
  5. Load table DataGrid
  6. function Loadgrid ()
  7. {
  8. //Load Data
  9. $ (' #cxdm '). DataGrid ({
  10. Width: ' auto ',
  11. Height:
  12. Striped: true,
  13. Singleselect: True,
  14. URL:' getpsnewconsultlist.action ',
  15. //queryparams:{},
  16. Loadmsg:' data loading please later ... ',
  17. Pagination: true,
  18. Rownumbers: True,
  19. columns:[[
  20. {field:' Adviceid ', title: ' Communication number ', align: ' center ', width:getwidth (0.2)},
  21. {field:' Consulter ', title: ' the ' align ', ' Center ', width:getwidth (0.45),
  22. //Add super-chain and pass in the future as a parameter
  23. Formatter:function (Val,rec) {
  24. //alert (Rec.adviceid);
  25. return "<a href= ' jsp/proposal/psconsultview.jsp?id=" +rec.adviceid+">" +val+"</a>";
  26. }
  27. },
  28. {field:' content ', title: ' state ', align: ' center ', width:getwidth (0.2)},
  29. {field:' Replynumber ', title: ' number of replies ', Align: ' center ', width:getwidth (0.05)}
  30. ]]
  31. });
  32. }
  33. Add parameters for Loadgrid ()
  34. var queryparams = $ (' #cxdm '). DataGrid (' Options '). Queryparams;
  35. queryparams.who = Who.value;
  36. Queryparams.type = Type.value;
  37. Queryparams.searchtype = Searchtype.value;
  38. Queryparams.keyword = Keyword.value;
  39. //Reload data for DataGrid
  40. $ ("#cxdm"). DataGrid (' reload ');

How the DataGrid adds parameters

  1. Add parameters for Loadgrid ()
  2. var queryparams = $ (' #cxdm '). DataGrid (' Options '). Queryparams;
  3. queryparams.who = Who.value;
  4. Queryparams.type = Type.value;
  5. Queryparams.searchtype = Searchtype.value;
  6. Queryparams.keyword = Keyword.value;
  7. //Reload data for DataGrid
  8. $ ("#cxdm"). DataGrid (' reload ');

Or add them directly to the URL.

    1. $ (' #repeatpspolal '). DataGrid ({
    2. Title:' repeated proposals for the first minute ',
    3. Loadmsg:"Data loading, please later ...",
    4. Region:' North ',
    5. URL:"getrepeatps.action?documentnumber=" +documentnumber+"&simdegree=" +simdegree,
    6. 。。。。。。

Action Layer

  1. Current page number
  2. private int page;
  3. .........
  4. Comment Result set
  5. Private list<object> rows;
  6. ...........
  7. @SuppressWarnings ("unchecked")
  8. Public String getpsnewconsultlist () throws globalexception {
  9. //Gets the number of rows displayed per page
  10. int pagerows=10;
  11. if (null!=request.getparameter ("Rows")) {
  12. Pagerows=integer.parseint (Request.getparameter ("Rows"). toString ());
  13. }
  14. ...........
  15. //Get result set
  16. this.setrows (Proposalservice.getpsnewconsultlist (consulter,consultee,type,psid,pscontent,pagerows* (page-  1) +1,pagerows*page));
  17. //Get the total number of records
  18. this.settotal (100);
  19. ...............
  20. }

The page is passed in by the DataGrid, and when the user selects the number of rows displayed per page in the lower-left corner of the DataGrid, the DataGrid appends the value as an argument to the URL passed into the action, and the name is called page. Also, the total row count of results is passed to the DataGrid for paging

It is not known whether the DataGrid is misconfigured or the Bug,datagrid result set of the DataGrid and the number of rows displayed per page are called rows, with the same name.

As a workaround, the result set is still called rows, but the list type is changed to object instead of the entity type, and the number of rows displayed per page is obtained by request

When the action is configured, to inherit Json-default,json-default inherits from Struts-default, also configure the output result type to be JSON

  1. <action name="getpsnewconsultlist" class="proposalconsultaction" method= "Getpsnewconsultlist" >
  2. <result name="Success" type="json" >
  3. <param name="Includeproperties" >
  4. ^rows\[\d+\]\.\w+,total
  5. </param>
  6. <param name="NoCache" >true</param>
  7. <param name="Ignorehierarchy" >false</param>
  8. </result>
  9. </action>

Service Layer

    1. @SuppressWarnings ("unchecked")
    2. Public List getpsnewconsultlist (String consulter,string consultee,string type,string psid,string pscontent, int pagerows,int page) throws Exception {
    3. return Proposaldao.getpsnewconsultlist (consulter,consultee,type,psid,pscontent,pagerows,page);
    4. }

The DAO layer simply joins the data loop in the resultset to the entity attribute and then joins the entity instance to the list, in the following form:

      1. list<person> list=New arraylist<person> ();
      2. person person=null;
      3. while (Rs.next ())
      4. {
      5. person=new Person ();
      6. Person.setid (i);
      7. Person.setname ("name" +i);
      8. List.add (person);
      9. }
      10. .........
      11. return list;

Easyui DataGrid use (Good)

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.