meta-config-basic.html 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <title>Test meta config and metachange event support</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. <!-- GC -->
  9. <script type="text/javascript" src="../../ext-all.js"></script>
  10. <script type="text/javascript" src="../shared/examples.js"></script>
  11. <script type="text/javascript" charset="utf-8">
  12. Ext.Loader.setConfig({enabled: true});
  13. Ext.require([
  14. 'Ext.grid.*',
  15. 'Ext.data.*',
  16. 'Ext.util.*',
  17. 'Ext.form.field.*'
  18. ]);
  19. Ext.define('MetaModel', {
  20. extend: 'Ext.data.Model'
  21. });
  22. Ext.onReady(function(){
  23. var metaStore = Ext.create('Ext.data.Store', {
  24. model: 'MetaModel',
  25. autoLoad: true,
  26. proxy: {
  27. type: 'ajax',
  28. url: 'meta-config-basic.php',
  29. reader: {
  30. type: 'json',
  31. root: 'data'
  32. }
  33. },
  34. listeners: {
  35. 'metachange': function(store, meta) {
  36. grid.reconfigure(store, meta.columns);
  37. }
  38. }
  39. });
  40. var rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
  41. clicksToMoveEditor: 1,
  42. autoCancel: false
  43. });
  44. var grid = Ext.create('Ext.grid.Panel', {
  45. width: 800,
  46. height: 300,
  47. title: 'Meta Grid',
  48. store: metaStore,
  49. columns: [],
  50. renderTo: 'grid-ct',
  51. tbar: [{
  52. text: 'Reload Metadata',
  53. handler: function() {
  54. metaStore.load();
  55. }
  56. }],
  57. plugins: rowEditing
  58. });
  59. });
  60. </script>
  61. </head>
  62. <body>
  63. <h1>Basic Meta Configuration</h1>
  64. <p>This example demonstrates reconfiguring a grid dynamically based on the metadata returned by the server<br>
  65. (requires PHP). Click the "Reload Metadata" button to see a new randomized column set and data in the grid.</p>
  66. <p>Note also that the grid is editable on double-click, and that the editors automatically update as well. See below for additional details.</p>
  67. <div id="grid-ct" style="width:800px;height:300px;"></div>
  68. <p style="margin-top:30px;">The server response is in this format:</p>
  69. <pre><code>{
  70. data: [{ ... }],
  71. msg: "...",
  72. total: 99,
  73. metaData: {
  74. fields: [{ ... }],
  75. columns: [{ ... }],
  76. idProperty: "id",
  77. messageProperty: "msg",
  78. root: "data"
  79. }
  80. }
  81. </code></pre>
  82. <p>The store/model automatically read the <code>fields</code> config to reconfigure the data model, but you can add any
  83. additional custom data into the <code>metaData</code> that you need. In this example we've added a <code>columns</code>
  84. config that contains a grid-specific column configuration that can be passed to the <code>grid.reconfigure()</code> method
  85. in the store's load event handler. You could easily add other widget-specific configurations into the response as well.</p>
  86. </body>
  87. </html>