You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.9 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <title>Grid with DataWriter Example</title>
  5. <link rel="stylesheet" type="text/css" href="../../resources/css/ext-all.css" />
  6. <!-- GC -->
  7. <!-- LIBS -->
  8. <script type="text/javascript" src="../../adapter/ext/ext-base.js"></script>
  9. <!-- ENDLIBS -->
  10. <script type="text/javascript" src="../../ext-all.js"></script>
  11. <script type="text/javascript" src="../shared/extjs/App.js"></script>
  12. <script type="text/javascript" src="writer.js"></script>
  13. <script type="text/javascript" src="UserForm.js"></script>
  14. <script type="text/javascript" src="UserGrid.js"></script>
  15. <!-- Common Styles for the examples -->
  16. <link rel="stylesheet" type="text/css" href="../shared/examples.css" />
  17. <link rel="stylesheet" type="text/css" href="../shared/icons/silk.css" />
  18. </head>
  19. <body>
  20. <script type="text/javascript" src="../shared/examples.js"></script><!-- EXAMPLES -->
  21. <h1>Ext.data.DataWriter Example</h1>
  22. <p>This example shows how to implement a Writer for your Store. A Writer-enabled Store frees you from having to manually compose Ajax requests
  23. to perform CRUD actions on a Store.</p>
  24. <p>Note that the js is not minified so it is readable. See <a href="writer.js">writer.js</a>, <a href="UserForm.js">UserForm.js</a> and
  25. <a href="UserGrid.js">UserGrid.js</a>.</p>
  26. <p>The HttpProxy plugged into the store in this example uses the new <em>api</em> configuration instead of an <em>url</em>.
  27. A simple MVC-like php backend has been created for this example which simulates a database by storing records in $_SESSION. See the file /remote/app/controllers/users.php. You may have to configure
  28. your web-server to allow scripts to be executed in the /examples directory.</p>
  29. <code><pre>
  30. var proxy = new Ext.data.HttpProxy({
  31. api: {
  32. read : 'app.php/users/read',
  33. create : 'app.php/users/create',
  34. update : 'app.php/users/update',
  35. destroy : 'app.php/users/destroy'
  36. }
  37. });
  38. </pre></code>
  39. <p>Take note of the requests being generated in Firebug as you interact with the Grid and Form.</p>
  40. <p>An <b>Error has been simulated</b> on the server-side: Attempting to update a record having ODD-numbered id will generate this errror.
  41. Responses from the update action will have successProperty === false along with a message. This error can be handled by
  42. listening to the <b>"exception"</b> event upon your Store.</p>
  43. <code><pre>
  44. exception : function(proxy, type, action, options, res, arg) {
  45. if (type === 'remote') {
  46. Ext.Msg.show({
  47. title: 'REMOTE EXCEPTION',
  48. msg: res.message,
  49. icon: Ext.MessageBox.ERROR
  50. });
  51. }
  52. }
  53. </pre></code>
  54. <p><b>Note: This new "exception" event supercedes the old loadexception event which is now deprecated.</b></p>
  55. <div class="container" style="width:500px">
  56. <div id="user-form"></div>
  57. <div id="user-grid"></div>
  58. </div>
  59. </body>
  60. </html>