课程表

Ext.js课程

工具箱
速查手册

Ext.js 网格

当前位置:免费教程 » JS/JS库/框架 » Ext.js

描述

网格:这个组件是显示数据的简单组件,它是以表格格式存储在Ext.data.Store中的记录的集合。

语法

这里是创建网格的简单语法

  1. Ext.create('Ext.grid.Panel',{
  2. grid properties..
  3. columns : [Columns]
  4. });

下面是一个简单的例子显示网格

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <link href="https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/theme-classic/resources/theme-classic-all.css" rel="stylesheet" />
  5. <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/ext-all.js"></script>
  6. <script type="text/javascript">
  7. // Creation of data model
  8. Ext.define('StudentDataModel', {
  9. extend: 'Ext.data.Model',
  10. fields: [
  11. {name: 'name', mapping : 'name'},
  12. {name: 'age', mapping : 'age'},
  13. {name: 'marks', mapping : 'marks'}
  14. ]
  15. });
  16. Ext.onReady(function(){
  17. // Store data
  18. var myData = [
  19. { name : "Asha", age : "16", marks : "90" },
  20. { name : "Vinit", age : "18", marks : "95" },
  21. { name : "Anand", age : "20", marks : "68" },
  22. { name : "Niharika", age : "21", marks : "86" },
  23. { name : "Manali", age : "22", marks : "57" }
  24. ];
  25. // Creation of first grid store
  26. var gridStore = Ext.create('Ext.data.Store', {
  27. model: 'StudentDataModel',
  28. data: myData
  29. });
  30. // Creation of first grid
  31. Ext.create('Ext.grid.Panel', {
  32. id : 'gridId',
  33. store : gridStore,
  34. stripeRows : true,
  35. title : 'Students Grid', // Title for the grid
  36. renderTo :'gridDiv', // Div id where the grid has to be rendered
  37. width : 600,
  38. collapsible : true, // property to collapse grid
  39. enableColumnMove :true, // property which alllows column to move to different position by dragging that column.
  40. enableColumnResize:true, // property which allows to resize column run time.
  41. columns :
  42. [{
  43. header: "Student Name",
  44. dataIndex: 'name',
  45. id : 'name',
  46. flex: 1, // property defines the amount of space this column is going to take in the grid container with respect to all.
  47. sortable: true, // property to sort grid column data.
  48. hideable: true // property which allows column to be hidden run time on user request.
  49. },{
  50. header: "Age",
  51. dataIndex: 'age',
  52. flex: .5,
  53. sortable: true,
  54. hideable: false // this column will not be available to be hidden.
  55. },{
  56. header: "Marks",
  57. dataIndex: 'marks',
  58. flex: .5,
  59. sortable: true,
  60. // renderer is used to manipulate data based on some conditions here who ever has marks greater than 75 will be displayed as 'Distinction' else 'Non Distinction'.
  61. renderer : function (value, metadata, record, rowIndex, colIndex, store) {
  62. if (value > 75) {
  63. return "Distinction";
  64. } else {
  65. return "Non Distinction";
  66. }
  67. }
  68. }]
  69. });
  70. });
  71. </script>
  72. </head>
  73. <body>
  74. <div id = "gridDiv"></div>
  75. </body>
  76. </html>

尝试一下

网格属性:

可折叠:此属性用于向网格添加折叠功能。 在网格属性中添加“Collapsible:true”功能以添加此功能。
排序:此属性是为网格添加排序功能。 在网格中添加列属性“sortable:true”以应用排序ASC / DESC。 默认情况下为true,因此如果您不想显示此功能,可以将其设为false。

  1. columns : [{
  2. header: "Student Name",
  3. dataIndex: 'name',
  4. id : 'name',
  5. flex: 1,
  6. sortable: true // property to sort grid column data
  7. }]

默认情况下,可以使用属性分类器应用soring:{property:'id',direction:'ASC'} In store。 在将数据呈现到网格之前,它将基于分拣机中提供的属性和给定的方向对网格数据进行分类。
启用列调整大小:可以使用网格属性“enableColumnResize:true”调整列的大小(可以增大或减小其宽度)。
列可隐藏:在网格中添加列属性“hideable:true”,使列显示为隐藏或显示。 默认情况下为true,因此如果您不想显示此功能,可以将其设为false。

  1. columns : [{
  2. header: "Student Name",
  3. dataIndex: 'name',
  4. id : 'name',
  5. flex: 1,
  6. sortable: true,
  7. hideable: true // property which allows column to be hidden run time on user request
  8. }]

可拖动列:添加列属性“enableColumnMove:true”是网格属性,我们可以使用它移动网格中的列。
渲染器:这是基于我们从商店获得的数据显示网格数据的自定义视图的属性。

  1. columns : [{
  2. header: "Marks",
  3. dataIndex: 'marks',
  4. flex: .5,
  5. sortable: true,
  6. // renderer is used to manipulate data based on some conditions here who ever has marks greater than 75 will be displayed as 'Distinction' else 'Non Distinction'.
  7. renderer : function (value, metadata, record, rowIndex, colIndex, store) {
  8. if (value > 75) {
  9. return "Distinction";
  10. } else {
  11. return "Non Distinction";
  12. }
  13. }
  14. }]
转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号