Extjs4 Study Notes (17th)-lock the header (locking grid) Function

Source: Internet
Author: User

In exjts4, we can lock the header (locking grid. The instance enables the grid to lock the table header. The locked columns are fixed (if there is a horizontal scroll bar ). The locked Column cannot be removed. For convenience, some local data is constructed as test data.

JS Code:

 
  1. Ext. Require ([
  2. 'Ext. Grid .*',
  3. 'Ext. Data .*',
  4. 'Ext. util .*',
  5. 'Ext. state .*'
  6. ]);
  7. Ext. onready (function (){
  8. Ext. quicktips. INIT ();
  9. // Sample static data for the store
  10. VaR mydata = [
  11. ['3 M co', 71.72, 0.02, 0.03, '2017 am '],
  12. ['Alcoa inc', 29.01, 0.42, 1.47, '2017 am '],
  13. ['Altria group inc', 83.81, 0.28, 0.34, '2017 am '],
  14. ['American express company ', 52.55, 0.01, 0.02, '2017 am'],
  15. ['American International Group, Inc. ', 64.13, 0.31, 0.49, '2017 am'],
  16. ['At & T Inc. ', 31.61,-0.48,-1.54, '2017 am'],
  17. ['Boeing Co. ', 75.43, 0.53, 0.71, '2017 am'],
  18. ['Caterpillar Inc. ', 67.27, 0.92, 1.39, '2017 am'],
  19. ['Citigroup, Inc. ', 49.37, 0.02, 0.04, '2017 am'],
  20. ['E. I. Du Pont de Nemours and company', 40.48, 0.51, 1.28, '2017 am '],
  21. ['Exxon Mobil Corp ', 68.1,-0.43,-0.64, '2017 am'],
  22. ['General Electric Company ', 34.14,-0.08,-0.23, '2017 am'],
  23. ['General Motors Corporation ', 30.27, 1.09, 3.74, '2017 am'],
  24. ['Hewlett-Packard Co. ', 36.53,-0.03,-0.08, '2017 am'],
  25. ['Honeywell Intl inc', 38.77, 0.05, 0.13, '2017 am '],
  26. ['Intel Corporation ', 19.88, 0.31, 1.58, '2017 am'],
  27. ['International business machines ', 81.41, 0.44, 0.54, '2017 am'],
  28. ['Johnson & Johnson ', 64.72, 0.06, 0.09, '2017 am'],
  29. ['Jp Morgan & Chase & co', 45.73, 0.07, 0.15, '2017 am '],
  30. ['Mcdonald \'s Corporation ', 36.76, 0.86, 2.40, '2017 am'],
  31. ['Merck & Co., Inc. ', 40.96, 0.41, 1.01, '2017 am'],
  32. ['Microsoft origin', 25.84, 0.14, 0.54, '2017 am '],
  33. ['Pfizer inc', 27.96, 0.4, 1.45, '2017 am '],
  34. ['The Coca-Cola Company ', 45.07, 0.26, 0.58, '2017 am'],
  35. ['The Home Depot, Inc. ', 34.64, 0.35, 1.02, '2017 am'],
  36. ['The Procter & Gamble Company ', 61.91, 0.01, 0.02, '2017 am'],
  37. ['United Technologies Corporation ', 63.26, 0.55, 0.88, '2017 am'],
  38. ['Verizon communications ', 35.57, 0.39, 1.11, '2017 am'],
  39. ['Wal-Mart stores, Inc. ', 45.45, 0.73, 1.63, '2017 am']
  40. ];
  41. /**
  42. * Custom function used for column Renderer
  43. * @ Param {object} Val
  44. */
  45. Function Change (VAL ){
  46. If (Val> 0 ){
  47. Return '<span style = "color: green;">' + Val + '</span> ';
  48. } Else if (Val <0 ){
  49. Return '<span style = "color: red;">' + Val + '</span> ';
  50. }
  51. Return val;
  52. }
  53. /**
  54. * Custom function used for column Renderer
  55. * @ Param {object} Val
  56. */
  57. Function pctchange (VAL ){
  58. If (Val> 0 ){
  59. Return '<span style = "color: green;">' + Val + '% </span> ';
  60. } Else if (Val <0 ){
  61. Return '<span style = "color: red;">' + Val + '% </span> ';
  62. }
  63. Return val;
  64. }
  65. // Create the Data Store
  66. VaR store = ext. Create ('ext. Data. arraystore ',{
  67. Fields :[
  68. {Name: 'company '},
  69. {Name: 'price', type: 'float '},
  70. {Name: 'change', type: 'float '},
  71. {Name: 'pctchang', type: 'float '},
  72. {Name: 'lastchang', type: 'date', dateformat: 'n'/j h: '}
  73. ],
  74. Data: mydata
  75. });
  76. // Create the grid
  77. VaR grid = ext. Create ('ext. Grid. Panel ',{
  78. Store: store,
  79. Columnlines: True,
  80. Columns :[{
  81. Text: 'company ',
  82. Locked: True,
  83. Width: 200,
  84. Sortable: false,
  85. Dataindex: 'company'
  86. },{
  87. Text: 'price ',
  88. Width: 125,
  89. Sortable: True,
  90. Renderer: 'usmoney ',
  91. Dataindex: 'price'
  92. },{
  93. Text: 'change ',
  94. Width: 125,
  95. Sortable: True,
  96. Renderer: change,
  97. Dataindex: 'change'
  98. },{
  99. Text: '% change ',
  100. Width: 125,
  101. Sortable: True,
  102. Renderer: pctchange,
  103. Dataindex: 'pctchang'
  104. },{
  105. Text: 'Last updated ',
  106. Width: 135,
  107. Sortable: True,
  108. Renderer: Ext. util. format. daterenderer ('m/D/Y '),
  109. Dataindex: 'lastchange'
  110. }],
  111. Height: 350,
  112. Width: 600,
  113. Title: 'locking grid column ',
  114. Renderto: 'grid-example ',
  115. Viewconfig :{
  116. Striperows: True
  117. }
  118. });
  119. });

Save this code as: locking-grid.js. Because the Code renders the grid to a container with ID: Grid-example, we need to write a DIV in the HTML page to place the grid.

HTML code:

 
  1. <! Doctype HTML public "-// W3C // dtd html 4.01 // en" "http://www.w3.org/TR/html4/strict.dtd">
  2. <HTML>
  3. <Head>
  4. <Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
  5. <Title> locking grid column example </title>
  6. <LINK rel = "stylesheet" type = "text/CSS" href = "../resources/CSS/ext-all.css"/>
  7. <LINK rel = "stylesheet" type = "text/CSS" href = "../shared/example.css"/>
  8. <SCRIPT type = "text/JavaScript" src = "..././Bootstrap. js"> </SCRIPT>
  9. <SCRIPT type = "text/JavaScript" src = "locking-grid.js"> </SCRIPT>
  10. </Head>
  11. <Body>
  12. <Div id = "Grid-Example"> </div>
  13. </Body>
  14. </Html>

Note that you must pay attention to the path for leading CSS and JS files.

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.