Extjs4 Study Notes (6)-grid with multiple headers

Source: Internet
Author: User

Sometimes a grid with multiple headers is encountered during project creation. In extjs4, the implementation of multiple headers is very simple. This article describes how to implement the multi-header gird function.

In the previous article, we talked about how to implement the grid paging function (Address: www.mhzg.net/a/20115/201151811170246.html). On this basis, this article makes modifications to achieve the multi-header grid + paging function.

Let's take a look at it first:

 

The implementation code is as follows:

HTML code:

 
  1. <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  3. <Head>
  4. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
  5. <Title> GroupHeaderGrid-MHZG.NET </title>
  6. <LINK rel = "stylesheet" type = "text/CSS" href = "../resources/CSS/ext-all.css"/>
  7. <SCRIPT type = "text/JavaScript" src = "..././Bootstrap. js"> </SCRIPT>
  8. <SCRIPT type = "text/JavaScript" src = ".../locale/ext-lang-zh_CN.js"> </SCRIPT>
  9. <SCRIPT type = "text/JavaScript" src = "group-header.js"> </SCRIPT>
  10. </Head>
  11. <Body>
  12. <Div id = "Demo"> </div>
  13. </Body>
  14. </Html>

Group-header.js:

 
  1. Ext. Require ([
  2. 'Ext. Grid .*',
  3. 'Ext. toolbar. paging ',
  4. 'Ext. util .*',
  5. 'Ext. Data .*'
  6. ]);
  7. Ext. onready (function (){
  8. Ext. Define ('mydata ',{
  9. Extend: 'ext. Data. model ',
  10. Fields :[
  11. 'Title', 'author ',
  12. // You must specify mapping for the first field. You can omit other fields.
  13. {Name: 'hits ', type: 'int '},
  14. 'Addtime'
  15. ]
  16. });
  17. // Create a data source
  18. VaR store = ext. Create ('ext. Data. store ',{
  19. // Page size
  20. Pagesize: 50,
  21. Model: 'mydata ',
  22. // Whether to sort data on the server
  23. Remotesort: True,
  24. Proxy :{
  25. // Obtain data asynchronously. The URL here can be changed to any dynamic page, as long as JSON data is returned.
  26. Type: 'ajax ',
  27. URL: 'mydata. asp ',
  28. Reader :{
  29. Root: 'items ',
  30. Totalproperty: 'Total'
  31. },
  32. Simplesortmode: True
  33. },
  34. Sorters :[{
  35. // Sort fields.
  36. Property: 'others ',
  37. // Sorting type. The default value is ASC.
  38. Direction: 'desc'
  39. }]
  40. });
  41. // Create a grid
  42. VaR grid = ext. Create ('ext. Grid. Panel ',{
  43. Store: store,
  44. Columnlines: True,
  45. Columns :[{
  46. Text: "basic information ",
  47. Columns :[
  48. {Text: "title", width: 120, dataindex: 'title', sortable: true },
  49. {Text: "author", width: 200, dataindex: 'author', sortable: false },
  50. {Text: "clicks", width: 100, dataindex: 'hits ', sortable: true}]
  51. },
  52. {Text: "add time", width: 100, dataindex: 'addtime', sortable: true}
  53. ],
  54. Height: 400,
  55. Width: 520,
  56. X: 20,
  57. Y: 40,
  58. Title: 'example of multiple headers with grid pagination in extjs4 ',
  59. Disableselection: True,
  60. Loadmask: True,
  61. Renderto: 'Demo ',
  62. Viewconfig :{
  63. ID: 'gv ',
  64. Trackover: false,
  65. Striperows: false
  66. },
  67. Bbar: Ext. Create ('ext. pagingtoolbar ',{
  68. Store: store,
  69. Displayinfo: True,
  70. Displaymsg: 'Show {0}-{1} items, total {2} items ',
  71. Emptymsg: "No data"
  72. })
  73. })
  74. Store. loadpage (1 );
  75. })

JS Code:

1. Remember to load 'ext. util .*',

2. The width of the second-level header must be specified. If the width is not specified, an error is prompted ., In the red box, you must specify the width.

Server code, which is written in ASP. For more information, see the previous article.

 
  1. <%
  2. Response. contenttype = "text/html"
  3. Response. charset = "UTF-8"
  4. %>
  5. <%
  6. 'Return JSON data and customize some test data ..
  7. 'The parameter here is the same as ext3.x, but the difference is that the sorting field and sorting method use new attributes.
  8. 'Because this is the test data, only start and limit parameters are received. In the actual operation process, you can add sorts and Dir to the SQL order by statement.
  9. Start = request ("START ")
  10. Limit = request ("Limit ")
  11. If start = "" then
  12. Start = 0
  13. End if
  14. If Limit = "" then
  15. Limit = 50
  16. End if
  17. Sorts = Replace (TRIM (request. Form ("sort ")),"'","")
  18. Dir = Replace (TRIM (request. Form ("dir ")),"'","")
  19. Dim counts: counts = 300
  20. 'Note that the counts here is equivalent to Rs. recordcount, that is, the total number of records.
  21. Dim ls: ls = CINT (start) + CINT (Limit)
  22. If ls> = counts then
  23. Ls = counts
  24. End if
  25. Echo ("{")
  26. Echo ("Total "":")
  27. Echo ("& counts &""",")
  28. Echo ("" items "":[")
  29. For I = start + 1 to LS
  30. Echo ("{")
  31. Echo ("title" ":" "newstitle" & I &"""")
  32. Echo (",")
  33. Echo ("author" ":" "author" & I &"""")
  34. Echo (",")
  35. Echo ("hits" ":" & I &"""")
  36. Echo (",")
  37. Echo ("addtime" ":" & now ()&"""")
  38. Echo ("}")
  39. If I <ls then
  40. Echo (",")
  41. End if
  42. Next
  43. Echo ("]}")
  44. Function echo (STR)
  45. Response. Write (STR)
  46. End Function
  47. %>

 

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.