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.

1994 lines
89 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-data-Store-method-constructor'><span id='Ext-data-Store'>/**
  19. </span></span> * @class Ext.data.Store
  20. * @extends Ext.util.Observable
  21. * &lt;p&gt;The Store class encapsulates a client side cache of {@link Ext.data.Record Record}
  22. * objects which provide input data for Components such as the {@link Ext.grid.GridPanel GridPanel},
  23. * the {@link Ext.form.ComboBox ComboBox}, or the {@link Ext.DataView DataView}.&lt;/p&gt;
  24. * &lt;p&gt;&lt;u&gt;Retrieving Data&lt;/u&gt;&lt;/p&gt;
  25. * &lt;p&gt;A Store object may access a data object using:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  26. * &lt;li&gt;{@link #proxy configured implementation} of {@link Ext.data.DataProxy DataProxy}&lt;/li&gt;
  27. * &lt;li&gt;{@link #data} to automatically pass in data&lt;/li&gt;
  28. * &lt;li&gt;{@link #loadData} to manually pass in data&lt;/li&gt;
  29. * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
  30. * &lt;p&gt;&lt;u&gt;Reading Data&lt;/u&gt;&lt;/p&gt;
  31. * &lt;p&gt;A Store object has no inherent knowledge of the format of the data object (it could be
  32. * an Array, XML, or JSON). A Store object uses an appropriate {@link #reader configured implementation}
  33. * of a {@link Ext.data.DataReader DataReader} to create {@link Ext.data.Record Record} instances from the data
  34. * object.&lt;/p&gt;
  35. * &lt;p&gt;&lt;u&gt;Store Types&lt;/u&gt;&lt;/p&gt;
  36. * &lt;p&gt;There are several implementations of Store available which are customized for use with
  37. * a specific DataReader implementation. Here is an example using an ArrayStore which implicitly
  38. * creates a reader commensurate to an Array data object.&lt;/p&gt;
  39. * &lt;pre&gt;&lt;code&gt;
  40. var myStore = new Ext.data.ArrayStore({
  41. fields: ['fullname', 'first'],
  42. idIndex: 0 // id for each record will be the first element
  43. });
  44. * &lt;/code&gt;&lt;/pre&gt;
  45. * &lt;p&gt;For custom implementations create a basic {@link Ext.data.Store} configured as needed:&lt;/p&gt;
  46. * &lt;pre&gt;&lt;code&gt;
  47. // create a {@link Ext.data.Record Record} constructor:
  48. var rt = Ext.data.Record.create([
  49. {name: 'fullname'},
  50. {name: 'first'}
  51. ]);
  52. var myStore = new Ext.data.Store({
  53. // explicitly create reader
  54. reader: new Ext.data.ArrayReader(
  55. {
  56. idIndex: 0 // id for each record will be the first element
  57. },
  58. rt // recordType
  59. )
  60. });
  61. * &lt;/code&gt;&lt;/pre&gt;
  62. * &lt;p&gt;Load some data into store (note the data object is an array which corresponds to the reader):&lt;/p&gt;
  63. * &lt;pre&gt;&lt;code&gt;
  64. var myData = [
  65. [1, 'Fred Flintstone', 'Fred'], // note that id for the record is the first element
  66. [2, 'Barney Rubble', 'Barney']
  67. ];
  68. myStore.loadData(myData);
  69. * &lt;/code&gt;&lt;/pre&gt;
  70. * &lt;p&gt;Records are cached and made available through accessor functions. An example of adding
  71. * a record to the store:&lt;/p&gt;
  72. * &lt;pre&gt;&lt;code&gt;
  73. var defaultData = {
  74. fullname: 'Full Name',
  75. first: 'First Name'
  76. };
  77. var recId = 100; // provide unique id for the record
  78. var r = new myStore.recordType(defaultData, ++recId); // create new record
  79. myStore.{@link #insert}(0, r); // insert a new record into the store (also see {@link #add})
  80. * &lt;/code&gt;&lt;/pre&gt;
  81. * &lt;p&gt;&lt;u&gt;Writing Data&lt;/u&gt;&lt;/p&gt;
  82. * &lt;p&gt;And &lt;b&gt;new in Ext version 3&lt;/b&gt;, use the new {@link Ext.data.DataWriter DataWriter} to create an automated, &lt;a href=&quot;http://extjs.com/deploy/dev/examples/writer/writer.html&quot;&gt;Writable Store&lt;/a&gt;
  83. * along with &lt;a href=&quot;http://extjs.com/deploy/dev/examples/restful/restful.html&quot;&gt;RESTful features.&lt;/a&gt;
  84. * @constructor
  85. * Creates a new Store.
  86. * @param {Object} config A config object containing the objects needed for the Store to access data,
  87. * and read the data into Records.
  88. * @xtype store
  89. */
  90. Ext.data.Store = Ext.extend(Ext.util.Observable, {
  91. <span id='Ext-data-Store-cfg-storeId'> /**
  92. </span> * @cfg {String} storeId If passed, the id to use to register with the &lt;b&gt;{@link Ext.StoreMgr StoreMgr}&lt;/b&gt;.
  93. * &lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: if a (deprecated) &lt;tt&gt;{@link #id}&lt;/tt&gt; is specified it will supersede the &lt;tt&gt;storeId&lt;/tt&gt;
  94. * assignment.&lt;/p&gt;
  95. */
  96. <span id='Ext-data-Store-cfg-url'> /**
  97. </span> * @cfg {String} url If a &lt;tt&gt;{@link #proxy}&lt;/tt&gt; is not specified the &lt;tt&gt;url&lt;/tt&gt; will be used to
  98. * implicitly configure a {@link Ext.data.HttpProxy HttpProxy} if an &lt;tt&gt;url&lt;/tt&gt; is specified.
  99. * Typically this option, or the &lt;code&gt;{@link #data}&lt;/code&gt; option will be specified.
  100. */
  101. <span id='Ext-data-Store-cfg-autoLoad'> /**
  102. </span> * @cfg {Boolean/Object} autoLoad If &lt;tt&gt;{@link #data}&lt;/tt&gt; is not specified, and if &lt;tt&gt;autoLoad&lt;/tt&gt;
  103. * is &lt;tt&gt;true&lt;/tt&gt; or an &lt;tt&gt;Object&lt;/tt&gt;, this store's {@link #load} method is automatically called
  104. * after creation. If the value of &lt;tt&gt;autoLoad&lt;/tt&gt; is an &lt;tt&gt;Object&lt;/tt&gt;, this &lt;tt&gt;Object&lt;/tt&gt; will
  105. * be passed to the store's {@link #load} method.
  106. */
  107. <span id='Ext-data-Store-cfg-proxy'> /**
  108. </span> * @cfg {Ext.data.DataProxy} proxy The {@link Ext.data.DataProxy DataProxy} object which provides
  109. * access to a data object. See &lt;code&gt;{@link #url}&lt;/code&gt;.
  110. */
  111. <span id='Ext-data-Store-cfg-data'> /**
  112. </span> * @cfg {Array} data An inline data object readable by the &lt;code&gt;{@link #reader}&lt;/code&gt;.
  113. * Typically this option, or the &lt;code&gt;{@link #url}&lt;/code&gt; option will be specified.
  114. */
  115. <span id='Ext-data-Store-cfg-reader'> /**
  116. </span> * @cfg {Ext.data.DataReader} reader The {@link Ext.data.DataReader Reader} object which processes the
  117. * data object and returns an Array of {@link Ext.data.Record} objects which are cached keyed by their
  118. * &lt;b&gt;&lt;tt&gt;{@link Ext.data.Record#id id}&lt;/tt&gt;&lt;/b&gt; property.
  119. */
  120. <span id='Ext-data-Store-cfg-writer'> /**
  121. </span> * @cfg {Ext.data.DataWriter} writer
  122. * &lt;p&gt;The {@link Ext.data.DataWriter Writer} object which processes a record object for being written
  123. * to the server-side database.&lt;/p&gt;
  124. * &lt;br&gt;&lt;p&gt;When a writer is installed into a Store the {@link #add}, {@link #remove}, and {@link #update}
  125. * events on the store are monitored in order to remotely {@link #createRecords create records},
  126. * {@link #destroyRecord destroy records}, or {@link #updateRecord update records}.&lt;/p&gt;
  127. * &lt;br&gt;&lt;p&gt;The proxy for this store will relay any {@link #writexception} events to this store.&lt;/p&gt;
  128. * &lt;br&gt;&lt;p&gt;Sample implementation:
  129. * &lt;pre&gt;&lt;code&gt;
  130. var writer = new {@link Ext.data.JsonWriter}({
  131. encode: true,
  132. writeAllFields: true // write all fields, not just those that changed
  133. });
  134. // Typical Store collecting the Proxy, Reader and Writer together.
  135. var store = new Ext.data.Store({
  136. storeId: 'user',
  137. root: 'records',
  138. proxy: proxy,
  139. reader: reader,
  140. writer: writer, // &lt;-- plug a DataWriter into the store just as you would a Reader
  141. paramsAsHash: true,
  142. autoSave: false // &lt;-- false to delay executing create, update, destroy requests
  143. // until specifically told to do so.
  144. });
  145. * &lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
  146. */
  147. writer : undefined,
  148. <span id='Ext-data-Store-cfg-baseParams'> /**
  149. </span> * @cfg {Object} baseParams
  150. * &lt;p&gt;An object containing properties which are to be sent as parameters
  151. * for &lt;i&gt;every&lt;/i&gt; HTTP request.&lt;/p&gt;
  152. * &lt;p&gt;Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.&lt;/p&gt;
  153. * &lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: &lt;code&gt;baseParams&lt;/code&gt; may be superseded by any &lt;code&gt;params&lt;/code&gt;
  154. * specified in a &lt;code&gt;{@link #load}&lt;/code&gt; request, see &lt;code&gt;{@link #load}&lt;/code&gt;
  155. * for more details.&lt;/p&gt;
  156. * This property may be modified after creation using the &lt;code&gt;{@link #setBaseParam}&lt;/code&gt;
  157. * method.
  158. */
  159. <span id='Ext-data-Store-cfg-sortInfo'> /**
  160. </span> * @cfg {Object} sortInfo A config object to specify the sort order in the request of a Store's
  161. * {@link #load} operation. Note that for local sorting, the &lt;tt&gt;direction&lt;/tt&gt; property is
  162. * case-sensitive. See also {@link #remoteSort} and {@link #paramNames}.
  163. * For example:&lt;pre&gt;&lt;code&gt;
  164. sortInfo: {
  165. field: 'fieldName',
  166. direction: 'ASC' // or 'DESC' (case sensitive for local sorting)
  167. }
  168. &lt;/code&gt;&lt;/pre&gt;
  169. */
  170. <span id='Ext-data-Store-cfg-remoteSort'> /**
  171. </span> * @cfg {boolean} remoteSort &lt;tt&gt;true&lt;/tt&gt; if sorting is to be handled by requesting the &lt;tt&gt;{@link #proxy Proxy}&lt;/tt&gt;
  172. * to provide a refreshed version of the data object in sorted order, as opposed to sorting the Record cache
  173. * in place (defaults to &lt;tt&gt;false&lt;/tt&gt;).
  174. * &lt;p&gt;If &lt;tt&gt;remoteSort&lt;/tt&gt; is &lt;tt&gt;true&lt;/tt&gt;, then clicking on a {@link Ext.grid.Column Grid Column}'s
  175. * {@link Ext.grid.Column#header header} causes the current page to be requested from the server appending
  176. * the following two parameters to the &lt;b&gt;&lt;tt&gt;{@link #load params}&lt;/tt&gt;&lt;/b&gt;:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  177. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;sort&lt;/tt&gt;&lt;/b&gt; : String&lt;p class=&quot;sub-desc&quot;&gt;The &lt;tt&gt;name&lt;/tt&gt; (as specified in the Record's
  178. * {@link Ext.data.Field Field definition}) of the field to sort on.&lt;/p&gt;&lt;/li&gt;
  179. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;dir&lt;/tt&gt;&lt;/b&gt; : String&lt;p class=&quot;sub-desc&quot;&gt;The direction of the sort, 'ASC' or 'DESC' (case-sensitive).&lt;/p&gt;&lt;/li&gt;
  180. * &lt;/ul&gt;&lt;/div&gt;&lt;/p&gt;
  181. */
  182. remoteSort : false,
  183. <span id='Ext-data-Store-cfg-autoDestroy'> /**
  184. </span> * @cfg {Boolean} autoDestroy &lt;tt&gt;true&lt;/tt&gt; to destroy the store when the component the store is bound
  185. * to is destroyed (defaults to &lt;tt&gt;false&lt;/tt&gt;).
  186. * &lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: this should be set to true when using stores that are bound to only 1 component.&lt;/p&gt;
  187. */
  188. autoDestroy : false,
  189. <span id='Ext-data-Store-cfg-pruneModifiedRecords'> /**
  190. </span> * @cfg {Boolean} pruneModifiedRecords &lt;tt&gt;true&lt;/tt&gt; to clear all modified record information each time
  191. * the store is loaded or when a record is removed (defaults to &lt;tt&gt;false&lt;/tt&gt;). See {@link #getModifiedRecords}
  192. * for the accessor method to retrieve the modified records.
  193. */
  194. pruneModifiedRecords : false,
  195. <span id='Ext-data-Store-property-lastOptions'> /**
  196. </span> * Contains the last options object used as the parameter to the {@link #load} method. See {@link #load}
  197. * for the details of what this may contain. This may be useful for accessing any params which were used
  198. * to load the current Record cache.
  199. * @property
  200. */
  201. lastOptions : null,
  202. <span id='Ext-data-Store-cfg-autoSave'> /**
  203. </span> * @cfg {Boolean} autoSave
  204. * &lt;p&gt;Defaults to &lt;tt&gt;true&lt;/tt&gt; causing the store to automatically {@link #save} records to
  205. * the server when a record is modified (ie: becomes 'dirty'). Specify &lt;tt&gt;false&lt;/tt&gt; to manually call {@link #save}
  206. * to send all modifiedRecords to the server.&lt;/p&gt;
  207. * &lt;br&gt;&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: each CRUD action will be sent as a separate request.&lt;/p&gt;
  208. */
  209. autoSave : true,
  210. <span id='Ext-data-Store-cfg-batch'> /**
  211. </span> * @cfg {Boolean} batch
  212. * &lt;p&gt;Defaults to &lt;tt&gt;true&lt;/tt&gt; (unless &lt;code&gt;{@link #restful}:true&lt;/code&gt;). Multiple
  213. * requests for each CRUD action (CREATE, READ, UPDATE and DESTROY) will be combined
  214. * and sent as one transaction. Only applies when &lt;code&gt;{@link #autoSave}&lt;/code&gt; is set
  215. * to &lt;tt&gt;false&lt;/tt&gt;.&lt;/p&gt;
  216. * &lt;br&gt;&lt;p&gt;If Store is RESTful, the DataProxy is also RESTful, and a unique transaction is
  217. * generated for each record.&lt;/p&gt;
  218. */
  219. batch : true,
  220. <span id='Ext-data-Store-cfg-restful'> /**
  221. </span> * @cfg {Boolean} restful
  222. * Defaults to &lt;tt&gt;false&lt;/tt&gt;. Set to &lt;tt&gt;true&lt;/tt&gt; to have the Store and the set
  223. * Proxy operate in a RESTful manner. The store will automatically generate GET, POST,
  224. * PUT and DELETE requests to the server. The HTTP method used for any given CRUD
  225. * action is described in {@link Ext.data.Api#restActions}. For additional information
  226. * see {@link Ext.data.DataProxy#restful}.
  227. * &lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: if &lt;code&gt;{@link #restful}:true&lt;/code&gt; &lt;code&gt;batch&lt;/code&gt; will
  228. * internally be set to &lt;tt&gt;false&lt;/tt&gt;.&lt;/p&gt;
  229. */
  230. restful: false,
  231. <span id='Ext-data-Store-cfg-paramNames'> /**
  232. </span> * @cfg {Object} paramNames
  233. * &lt;p&gt;An object containing properties which specify the names of the paging and
  234. * sorting parameters passed to remote servers when loading blocks of data. By default, this
  235. * object takes the following form:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  236. {
  237. start : 'start', // The parameter name which specifies the start row
  238. limit : 'limit', // The parameter name which specifies number of rows to return
  239. sort : 'sort', // The parameter name which specifies the column to sort on
  240. dir : 'dir' // The parameter name which specifies the sort direction
  241. }
  242. &lt;/code&gt;&lt;/pre&gt;
  243. * &lt;p&gt;The server must produce the requested data block upon receipt of these parameter names.
  244. * If different parameter names are required, this property can be overriden using a configuration
  245. * property.&lt;/p&gt;
  246. * &lt;p&gt;A {@link Ext.PagingToolbar PagingToolbar} bound to this Store uses this property to determine
  247. * the parameter names to use in its {@link #load requests}.
  248. */
  249. paramNames : undefined,
  250. <span id='Ext-data-Store-cfg-defaultParamNames'> /**
  251. </span> * @cfg {Object} defaultParamNames
  252. * Provides the default values for the {@link #paramNames} property. To globally modify the parameters
  253. * for all stores, this object should be changed on the store prototype.
  254. */
  255. defaultParamNames : {
  256. start : 'start',
  257. limit : 'limit',
  258. sort : 'sort',
  259. dir : 'dir'
  260. },
  261. <span id='Ext-data-Store-property-isDestroyed'> isDestroyed: false,
  262. </span><span id='Ext-data-Store-property-hasMultiSort'> hasMultiSort: false,
  263. </span>
  264. <span id='Ext-data-Store-property-batchKey'> // private
  265. </span> batchKey : '_ext_batch_',
  266. constructor : function(config){
  267. <span id='Ext-data-Store-property-hasMultiSort'> /**
  268. </span> * @property hasMultiSort
  269. * @type Boolean
  270. * True if this store is currently sorted by more than one field/direction combination.
  271. */
  272. <span id='Ext-data-Store-property-isDestroyed'> /**
  273. </span> * @property isDestroyed
  274. * @type Boolean
  275. * True if the store has been destroyed already. Read only
  276. */
  277. this.data = new Ext.util.MixedCollection(false);
  278. this.data.getKey = function(o){
  279. return o.id;
  280. };
  281. // temporary removed-records cache
  282. this.removed = [];
  283. if(config &amp;&amp; config.data){
  284. this.inlineData = config.data;
  285. delete config.data;
  286. }
  287. Ext.apply(this, config);
  288. <span id='Ext-data-Store-property-baseParams'> /**
  289. </span> * See the &lt;code&gt;{@link #baseParams corresponding configuration option}&lt;/code&gt;
  290. * for a description of this property.
  291. * To modify this property see &lt;code&gt;{@link #setBaseParam}&lt;/code&gt;.
  292. * @property
  293. */
  294. this.baseParams = Ext.isObject(this.baseParams) ? this.baseParams : {};
  295. this.paramNames = Ext.applyIf(this.paramNames || {}, this.defaultParamNames);
  296. if((this.url || this.api) &amp;&amp; !this.proxy){
  297. this.proxy = new Ext.data.HttpProxy({url: this.url, api: this.api});
  298. }
  299. // If Store is RESTful, so too is the DataProxy
  300. if (this.restful === true &amp;&amp; this.proxy) {
  301. // When operating RESTfully, a unique transaction is generated for each record.
  302. // TODO might want to allow implemention of faux REST where batch is possible using RESTful routes only.
  303. this.batch = false;
  304. Ext.data.Api.restify(this.proxy);
  305. }
  306. if(this.reader){ // reader passed
  307. if(!this.recordType){
  308. this.recordType = this.reader.recordType;
  309. }
  310. if(this.reader.onMetaChange){
  311. this.reader.onMetaChange = this.reader.onMetaChange.createSequence(this.onMetaChange, this);
  312. }
  313. if (this.writer) { // writer passed
  314. if (this.writer instanceof(Ext.data.DataWriter) === false) { // &lt;-- config-object instead of instance.
  315. this.writer = this.buildWriter(this.writer);
  316. }
  317. this.writer.meta = this.reader.meta;
  318. this.pruneModifiedRecords = true;
  319. }
  320. }
  321. <span id='Ext-data-Store-property-recordType'> /**
  322. </span> * The {@link Ext.data.Record Record} constructor as supplied to (or created by) the
  323. * {@link Ext.data.DataReader Reader}. Read-only.
  324. * &lt;p&gt;If the Reader was constructed by passing in an Array of {@link Ext.data.Field} definition objects,
  325. * instead of a Record constructor, it will implicitly create a Record constructor from that Array (see
  326. * {@link Ext.data.Record}.{@link Ext.data.Record#create create} for additional details).&lt;/p&gt;
  327. * &lt;p&gt;This property may be used to create new Records of the type held in this Store, for example:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  328. // create the data store
  329. var store = new Ext.data.ArrayStore({
  330. autoDestroy: true,
  331. fields: [
  332. {name: 'company'},
  333. {name: 'price', type: 'float'},
  334. {name: 'change', type: 'float'},
  335. {name: 'pctChange', type: 'float'},
  336. {name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
  337. ]
  338. });
  339. store.loadData(myData);
  340. // create the Grid
  341. var grid = new Ext.grid.EditorGridPanel({
  342. store: store,
  343. colModel: new Ext.grid.ColumnModel({
  344. columns: [
  345. {id:'company', header: 'Company', width: 160, dataIndex: 'company'},
  346. {header: 'Price', renderer: 'usMoney', dataIndex: 'price'},
  347. {header: 'Change', renderer: change, dataIndex: 'change'},
  348. {header: '% Change', renderer: pctChange, dataIndex: 'pctChange'},
  349. {header: 'Last Updated', width: 85,
  350. renderer: Ext.util.Format.dateRenderer('m/d/Y'),
  351. dataIndex: 'lastChange'}
  352. ],
  353. defaults: {
  354. sortable: true,
  355. width: 75
  356. }
  357. }),
  358. autoExpandColumn: 'company', // match the id specified in the column model
  359. height:350,
  360. width:600,
  361. title:'Array Grid',
  362. tbar: [{
  363. text: 'Add Record',
  364. handler : function(){
  365. var defaultData = {
  366. change: 0,
  367. company: 'New Company',
  368. lastChange: (new Date()).clearTime(),
  369. pctChange: 0,
  370. price: 10
  371. };
  372. var recId = 3; // provide unique id
  373. var p = new store.recordType(defaultData, recId); // create new record
  374. grid.stopEditing();
  375. store.{@link #insert}(0, p); // insert a new record into the store (also see {@link #add})
  376. grid.startEditing(0, 0);
  377. }
  378. }]
  379. });
  380. * &lt;/code&gt;&lt;/pre&gt;
  381. * @property recordType
  382. * @type Function
  383. */
  384. if(this.recordType){
  385. <span id='Ext-data-Store-property-fields'> /**
  386. </span> * A {@link Ext.util.MixedCollection MixedCollection} containing the defined {@link Ext.data.Field Field}s
  387. * for the {@link Ext.data.Record Records} stored in this Store. Read-only.
  388. * @property fields
  389. * @type Ext.util.MixedCollection
  390. */
  391. this.fields = this.recordType.prototype.fields;
  392. }
  393. this.modified = [];
  394. this.addEvents(
  395. <span id='Ext-data-Store-event-datachanged'> /**
  396. </span> * @event datachanged
  397. * Fires when the data cache has changed in a bulk manner (e.g., it has been sorted, filtered, etc.) and a
  398. * widget that is using this Store as a Record cache should refresh its view.
  399. * @param {Store} this
  400. */
  401. 'datachanged',
  402. <span id='Ext-data-Store-event-metachange'> /**
  403. </span> * @event metachange
  404. * Fires when this store's reader provides new metadata (fields). This is currently only supported for JsonReaders.
  405. * @param {Store} this
  406. * @param {Object} meta The JSON metadata
  407. */
  408. 'metachange',
  409. <span id='Ext-data-Store-event-add'> /**
  410. </span> * @event add
  411. * Fires when Records have been {@link #add}ed to the Store
  412. * @param {Store} this
  413. * @param {Ext.data.Record[]} records The array of Records added
  414. * @param {Number} index The index at which the record(s) were added
  415. */
  416. 'add',
  417. <span id='Ext-data-Store-event-remove'> /**
  418. </span> * @event remove
  419. * Fires when a Record has been {@link #remove}d from the Store
  420. * @param {Store} this
  421. * @param {Ext.data.Record} record The Record that was removed
  422. * @param {Number} index The index at which the record was removed
  423. */
  424. 'remove',
  425. <span id='Ext-data-Store-event-update'> /**
  426. </span> * @event update
  427. * Fires when a Record has been updated
  428. * @param {Store} this
  429. * @param {Ext.data.Record} record The Record that was updated
  430. * @param {String} operation The update operation being performed. Value may be one of:
  431. * &lt;pre&gt;&lt;code&gt;
  432. Ext.data.Record.EDIT
  433. Ext.data.Record.REJECT
  434. Ext.data.Record.COMMIT
  435. * &lt;/code&gt;&lt;/pre&gt;
  436. */
  437. 'update',
  438. <span id='Ext-data-Store-event-clear'> /**
  439. </span> * @event clear
  440. * Fires when the data cache has been cleared.
  441. * @param {Store} this
  442. * @param {Record[]} records The records that were cleared.
  443. */
  444. 'clear',
  445. <span id='Ext-data-Store-event-exception'> /**
  446. </span> * @event exception
  447. * &lt;p&gt;Fires if an exception occurs in the Proxy during a remote request.
  448. * This event is relayed through the corresponding {@link Ext.data.DataProxy}.
  449. * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
  450. * for additional details.
  451. * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#exception exception}
  452. * for description.
  453. */
  454. 'exception',
  455. <span id='Ext-data-Store-event-beforeload'> /**
  456. </span> * @event beforeload
  457. * Fires before a request is made for a new data object. If the beforeload handler returns
  458. * &lt;tt&gt;false&lt;/tt&gt; the {@link #load} action will be canceled.
  459. * @param {Store} this
  460. * @param {Object} options The loading options that were specified (see {@link #load} for details)
  461. */
  462. 'beforeload',
  463. <span id='Ext-data-Store-event-load'> /**
  464. </span> * @event load
  465. * Fires after a new set of Records has been loaded.
  466. * @param {Store} this
  467. * @param {Ext.data.Record[]} records The Records that were loaded
  468. * @param {Object} options The loading options that were specified (see {@link #load} for details)
  469. */
  470. 'load',
  471. <span id='Ext-data-Store-event-loadexception'> /**
  472. </span> * @event loadexception
  473. * &lt;p&gt;This event is &lt;b&gt;deprecated&lt;/b&gt; in favor of the catch-all &lt;b&gt;&lt;code&gt;{@link #exception}&lt;/code&gt;&lt;/b&gt;
  474. * event instead.&lt;/p&gt;
  475. * &lt;p&gt;This event is relayed through the corresponding {@link Ext.data.DataProxy}.
  476. * See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
  477. * for additional details.
  478. * @param {misc} misc See {@link Ext.data.DataProxy}.{@link Ext.data.DataProxy#loadexception loadexception}
  479. * for description.
  480. */
  481. 'loadexception',
  482. <span id='Ext-data-Store-event-beforewrite'> /**
  483. </span> * @event beforewrite
  484. * @param {Ext.data.Store} store
  485. * @param {String} action [Ext.data.Api.actions.create|update|destroy]
  486. * @param {Record/Record[]} rs The Record(s) being written.
  487. * @param {Object} options The loading options that were specified. Edit &lt;code&gt;options.params&lt;/code&gt; to add Http parameters to the request. (see {@link #save} for details)
  488. * @param {Object} arg The callback's arg object passed to the {@link #request} function
  489. */
  490. 'beforewrite',
  491. <span id='Ext-data-Store-event-write'> /**
  492. </span> * @event write
  493. * Fires if the server returns 200 after an Ext.data.Api.actions CRUD action.
  494. * Success of the action is determined in the &lt;code&gt;result['successProperty']&lt;/code&gt;property (&lt;b&gt;NOTE&lt;/b&gt; for RESTful stores,
  495. * a simple 20x response is sufficient for the actions &quot;destroy&quot; and &quot;update&quot;. The &quot;create&quot; action should should return 200 along with a database pk).
  496. * @param {Ext.data.Store} store
  497. * @param {String} action [Ext.data.Api.actions.create|update|destroy]
  498. * @param {Object} result The 'data' picked-out out of the response for convenience.
  499. * @param {Ext.Direct.Transaction} res
  500. * @param {Record/Record[]} rs Store's records, the subject(s) of the write-action
  501. */
  502. 'write',
  503. <span id='Ext-data-Store-event-beforesave'> /**
  504. </span> * @event beforesave
  505. * Fires before a save action is called. A save encompasses destroying records, updating records and creating records.
  506. * @param {Ext.data.Store} store
  507. * @param {Object} data An object containing the data that is to be saved. The object will contain a key for each appropriate action,
  508. * with an array of records for each action.
  509. */
  510. 'beforesave',
  511. <span id='Ext-data-Store-event-save'> /**
  512. </span> * @event save
  513. * Fires after a save is completed. A save encompasses destroying records, updating records and creating records.
  514. * @param {Ext.data.Store} store
  515. * @param {Number} batch The identifier for the batch that was saved.
  516. * @param {Object} data An object containing the data that is to be saved. The object will contain a key for each appropriate action,
  517. * with an array of records for each action.
  518. */
  519. 'save'
  520. );
  521. if(this.proxy){
  522. // TODO remove deprecated loadexception with ext-3.0.1
  523. this.relayEvents(this.proxy, ['loadexception', 'exception']);
  524. }
  525. // With a writer set for the Store, we want to listen to add/remove events to remotely create/destroy records.
  526. if (this.writer) {
  527. this.on({
  528. scope: this,
  529. add: this.createRecords,
  530. remove: this.destroyRecord,
  531. update: this.updateRecord,
  532. clear: this.onClear
  533. });
  534. }
  535. this.sortToggle = {};
  536. if(this.sortField){
  537. this.setDefaultSort(this.sortField, this.sortDir);
  538. }else if(this.sortInfo){
  539. this.setDefaultSort(this.sortInfo.field, this.sortInfo.direction);
  540. }
  541. Ext.data.Store.superclass.constructor.call(this);
  542. if(this.id){
  543. this.storeId = this.id;
  544. delete this.id;
  545. }
  546. if(this.storeId){
  547. Ext.StoreMgr.register(this);
  548. }
  549. if(this.inlineData){
  550. this.loadData(this.inlineData);
  551. delete this.inlineData;
  552. }else if(this.autoLoad){
  553. this.load.defer(10, this, [
  554. typeof this.autoLoad == 'object' ?
  555. this.autoLoad : undefined]);
  556. }
  557. // used internally to uniquely identify a batch
  558. this.batchCounter = 0;
  559. this.batches = {};
  560. },
  561. <span id='Ext-data-Store-method-buildWriter'> /**
  562. </span> * builds a DataWriter instance when Store constructor is provided with a writer config-object instead of an instace.
  563. * @param {Object} config Writer configuration
  564. * @return {Ext.data.DataWriter}
  565. * @private
  566. */
  567. buildWriter : function(config) {
  568. var klass = undefined,
  569. type = (config.format || 'json').toLowerCase();
  570. switch (type) {
  571. case 'json':
  572. klass = Ext.data.JsonWriter;
  573. break;
  574. case 'xml':
  575. klass = Ext.data.XmlWriter;
  576. break;
  577. default:
  578. klass = Ext.data.JsonWriter;
  579. }
  580. return new klass(config);
  581. },
  582. <span id='Ext-data-Store-method-destroy'> /**
  583. </span> * Destroys the store.
  584. */
  585. destroy : function(){
  586. if(!this.isDestroyed){
  587. if(this.storeId){
  588. Ext.StoreMgr.unregister(this);
  589. }
  590. this.clearData();
  591. this.data = null;
  592. Ext.destroy(this.proxy);
  593. this.reader = this.writer = null;
  594. this.purgeListeners();
  595. this.isDestroyed = true;
  596. }
  597. },
  598. <span id='Ext-data-Store-method-add'> /**
  599. </span> * Add Records to the Store and fires the {@link #add} event. To add Records
  600. * to the store from a remote source use &lt;code&gt;{@link #load}({add:true})&lt;/code&gt;.
  601. * See also &lt;code&gt;{@link #recordType}&lt;/code&gt; and &lt;code&gt;{@link #insert}&lt;/code&gt;.
  602. * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects
  603. * to add to the cache. See {@link #recordType}.
  604. */
  605. add : function(records) {
  606. var i, len, record, index;
  607. records = [].concat(records);
  608. if (records.length &lt; 1) {
  609. return;
  610. }
  611. for (i = 0, len = records.length; i &lt; len; i++) {
  612. record = records[i];
  613. record.join(this);
  614. if (record.dirty || record.phantom) {
  615. this.modified.push(record);
  616. }
  617. }
  618. index = this.data.length;
  619. this.data.addAll(records);
  620. if (this.snapshot) {
  621. this.snapshot.addAll(records);
  622. }
  623. this.fireEvent('add', this, records, index);
  624. },
  625. <span id='Ext-data-Store-method-addSorted'> /**
  626. </span> * (Local sort only) Inserts the passed Record into the Store at the index where it
  627. * should go based on the current sort information.
  628. * @param {Ext.data.Record} record
  629. */
  630. addSorted : function(record){
  631. var index = this.findInsertIndex(record);
  632. this.insert(index, record);
  633. },
  634. <span id='Ext-data-Store-method-doUpdate'> /**
  635. </span> * @private
  636. * Update a record within the store with a new reference
  637. */
  638. doUpdate: function(rec){
  639. var id = rec.id;
  640. // unjoin the old record
  641. this.getById(id).join(null);
  642. this.data.replace(id, rec);
  643. if (this.snapshot) {
  644. this.snapshot.replace(id, rec);
  645. }
  646. rec.join(this);
  647. this.fireEvent('update', this, rec, Ext.data.Record.COMMIT);
  648. },
  649. <span id='Ext-data-Store-method-remove'> /**
  650. </span> * Remove Records from the Store and fires the {@link #remove} event.
  651. * @param {Ext.data.Record/Ext.data.Record[]} record The record object or array of records to remove from the cache.
  652. */
  653. remove : function(record){
  654. if(Ext.isArray(record)){
  655. Ext.each(record, function(r){
  656. this.remove(r);
  657. }, this);
  658. return;
  659. }
  660. var index = this.data.indexOf(record);
  661. if(index &gt; -1){
  662. record.join(null);
  663. this.data.removeAt(index);
  664. }
  665. if(this.pruneModifiedRecords){
  666. this.modified.remove(record);
  667. }
  668. if(this.snapshot){
  669. this.snapshot.remove(record);
  670. }
  671. if(index &gt; -1){
  672. this.fireEvent('remove', this, record, index);
  673. }
  674. },
  675. <span id='Ext-data-Store-method-removeAt'> /**
  676. </span> * Remove a Record from the Store at the specified index. Fires the {@link #remove} event.
  677. * @param {Number} index The index of the record to remove.
  678. */
  679. removeAt : function(index){
  680. this.remove(this.getAt(index));
  681. },
  682. <span id='Ext-data-Store-method-removeAll'> /**
  683. </span> * Remove all Records from the Store and fires the {@link #clear} event.
  684. * @param {Boolean} silent [false] Defaults to &lt;tt&gt;false&lt;/tt&gt;. Set &lt;tt&gt;true&lt;/tt&gt; to not fire clear event.
  685. */
  686. removeAll : function(silent){
  687. var items = [];
  688. this.each(function(rec){
  689. items.push(rec);
  690. });
  691. this.clearData();
  692. if(this.snapshot){
  693. this.snapshot.clear();
  694. }
  695. if(this.pruneModifiedRecords){
  696. this.modified = [];
  697. }
  698. if (silent !== true) { // &lt;-- prevents write-actions when we just want to clear a store.
  699. this.fireEvent('clear', this, items);
  700. }
  701. },
  702. <span id='Ext-data-Store-method-onClear'> // private
  703. </span> onClear: function(store, records){
  704. Ext.each(records, function(rec, index){
  705. this.destroyRecord(this, rec, index);
  706. }, this);
  707. },
  708. <span id='Ext-data-Store-method-insert'> /**
  709. </span> * Inserts Records into the Store at the given index and fires the {@link #add} event.
  710. * See also &lt;code&gt;{@link #add}&lt;/code&gt; and &lt;code&gt;{@link #addSorted}&lt;/code&gt;.
  711. * @param {Number} index The start index at which to insert the passed Records.
  712. * @param {Ext.data.Record[]} records An Array of Ext.data.Record objects to add to the cache.
  713. */
  714. insert : function(index, records) {
  715. var i, len, record;
  716. records = [].concat(records);
  717. for (i = 0, len = records.length; i &lt; len; i++) {
  718. record = records[i];
  719. this.data.insert(index + i, record);
  720. record.join(this);
  721. if (record.dirty || record.phantom) {
  722. this.modified.push(record);
  723. }
  724. }
  725. if (this.snapshot) {
  726. this.snapshot.addAll(records);
  727. }
  728. this.fireEvent('add', this, records, index);
  729. },
  730. <span id='Ext-data-Store-method-indexOf'> /**
  731. </span> * Get the index within the cache of the passed Record.
  732. * @param {Ext.data.Record} record The Ext.data.Record object to find.
  733. * @return {Number} The index of the passed Record. Returns -1 if not found.
  734. */
  735. indexOf : function(record){
  736. return this.data.indexOf(record);
  737. },
  738. <span id='Ext-data-Store-method-indexOfId'> /**
  739. </span> * Get the index within the cache of the Record with the passed id.
  740. * @param {String} id The id of the Record to find.
  741. * @return {Number} The index of the Record. Returns -1 if not found.
  742. */
  743. indexOfId : function(id){
  744. return this.data.indexOfKey(id);
  745. },
  746. <span id='Ext-data-Store-method-getById'> /**
  747. </span> * Get the Record with the specified id.
  748. * @param {String} id The id of the Record to find.
  749. * @return {Ext.data.Record} The Record with the passed id. Returns undefined if not found.
  750. */
  751. getById : function(id){
  752. return (this.snapshot || this.data).key(id);
  753. },
  754. <span id='Ext-data-Store-method-getAt'> /**
  755. </span> * Get the Record at the specified index.
  756. * @param {Number} index The index of the Record to find.
  757. * @return {Ext.data.Record} The Record at the passed index. Returns undefined if not found.
  758. */
  759. getAt : function(index){
  760. return this.data.itemAt(index);
  761. },
  762. <span id='Ext-data-Store-method-getRange'> /**
  763. </span> * Returns a range of Records between specified indices.
  764. * @param {Number} startIndex (optional) The starting index (defaults to 0)
  765. * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
  766. * @return {Ext.data.Record[]} An array of Records
  767. */
  768. getRange : function(start, end){
  769. return this.data.getRange(start, end);
  770. },
  771. <span id='Ext-data-Store-method-storeOptions'> // private
  772. </span> storeOptions : function(o){
  773. o = Ext.apply({}, o);
  774. delete o.callback;
  775. delete o.scope;
  776. this.lastOptions = o;
  777. },
  778. <span id='Ext-data-Store-method-clearData'> // private
  779. </span> clearData: function(){
  780. this.data.each(function(rec) {
  781. rec.join(null);
  782. });
  783. this.data.clear();
  784. },
  785. <span id='Ext-data-Store-method-load'> /**
  786. </span> * &lt;p&gt;Loads the Record cache from the configured &lt;tt&gt;{@link #proxy}&lt;/tt&gt; using the configured &lt;tt&gt;{@link #reader}&lt;/tt&gt;.&lt;/p&gt;
  787. * &lt;br&gt;&lt;p&gt;Notes:&lt;/p&gt;&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  788. * &lt;li&gt;&lt;b&gt;&lt;u&gt;Important&lt;/u&gt;&lt;/b&gt;: loading is asynchronous! This call will return before the new data has been
  789. * loaded. To perform any post-processing where information from the load call is required, specify
  790. * the &lt;tt&gt;callback&lt;/tt&gt; function to be called, or use a {@link Ext.util.Observable#listeners a 'load' event handler}.&lt;/li&gt;
  791. * &lt;li&gt;If using {@link Ext.PagingToolbar remote paging}, the first load call must specify the &lt;tt&gt;start&lt;/tt&gt; and &lt;tt&gt;limit&lt;/tt&gt;
  792. * properties in the &lt;code&gt;options.params&lt;/code&gt; property to establish the initial position within the
  793. * dataset, and the number of Records to cache on each read from the Proxy.&lt;/li&gt;
  794. * &lt;li&gt;If using {@link #remoteSort remote sorting}, the configured &lt;code&gt;{@link #sortInfo}&lt;/code&gt;
  795. * will be automatically included with the posted parameters according to the specified
  796. * &lt;code&gt;{@link #paramNames}&lt;/code&gt;.&lt;/li&gt;
  797. * &lt;/ul&gt;&lt;/div&gt;
  798. * @param {Object} options An object containing properties which control loading options:&lt;ul&gt;
  799. * &lt;li&gt;&lt;b&gt;&lt;tt&gt;params&lt;/tt&gt;&lt;/b&gt; :Object&lt;div class=&quot;sub-desc&quot;&gt;&lt;p&gt;An object containing properties to pass as HTTP
  800. * parameters to a remote data source. &lt;b&gt;Note&lt;/b&gt;: &lt;code&gt;params&lt;/code&gt; will override any
  801. * &lt;code&gt;{@link #baseParams}&lt;/code&gt; of the same name.&lt;/p&gt;
  802. * &lt;p&gt;Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.&lt;/p&gt;&lt;/div&gt;&lt;/li&gt;
  803. * &lt;li&gt;&lt;b&gt;callback&lt;/b&gt; : Function&lt;div class=&quot;sub-desc&quot;&gt;&lt;p&gt;A function to be called after the Records
  804. * have been loaded. The callback is called after the load event is fired, and is passed the following arguments:&lt;ul&gt;
  805. * &lt;li&gt;r : Ext.data.Record[] An Array of Records loaded.&lt;/li&gt;
  806. * &lt;li&gt;options : Options object from the load call.&lt;/li&gt;
  807. * &lt;li&gt;success : Boolean success indicator.&lt;/li&gt;&lt;/ul&gt;&lt;/p&gt;&lt;/div&gt;&lt;/li&gt;
  808. * &lt;li&gt;&lt;b&gt;scope&lt;/b&gt; : Object&lt;div class=&quot;sub-desc&quot;&gt;&lt;p&gt;Scope with which to call the callback (defaults
  809. * to the Store object)&lt;/p&gt;&lt;/div&gt;&lt;/li&gt;
  810. * &lt;li&gt;&lt;b&gt;add&lt;/b&gt; : Boolean&lt;div class=&quot;sub-desc&quot;&gt;&lt;p&gt;Indicator to append loaded records rather than
  811. * replace the current cache. &lt;b&gt;Note&lt;/b&gt;: see note for &lt;tt&gt;{@link #loadData}&lt;/tt&gt;&lt;/p&gt;&lt;/div&gt;&lt;/li&gt;
  812. * &lt;/ul&gt;
  813. * @return {Boolean} If the &lt;i&gt;developer&lt;/i&gt; provided &lt;tt&gt;{@link #beforeload}&lt;/tt&gt; event handler returns
  814. * &lt;tt&gt;false&lt;/tt&gt;, the load call will abort and will return &lt;tt&gt;false&lt;/tt&gt;; otherwise will return &lt;tt&gt;true&lt;/tt&gt;.
  815. */
  816. load : function(options) {
  817. options = Ext.apply({}, options);
  818. this.storeOptions(options);
  819. if(this.sortInfo &amp;&amp; this.remoteSort){
  820. var pn = this.paramNames;
  821. options.params = Ext.apply({}, options.params);
  822. options.params[pn.sort] = this.sortInfo.field;
  823. options.params[pn.dir] = this.sortInfo.direction;
  824. }
  825. try {
  826. return this.execute('read', null, options); // &lt;-- null represents rs. No rs for load actions.
  827. } catch(e) {
  828. this.handleException(e);
  829. return false;
  830. }
  831. },
  832. <span id='Ext-data-Store-method-updateRecord'> /**
  833. </span> * updateRecord Should not be used directly. This method will be called automatically if a Writer is set.
  834. * Listens to 'update' event.
  835. * @param {Object} store
  836. * @param {Object} record
  837. * @param {Object} action
  838. * @private
  839. */
  840. updateRecord : function(store, record, action) {
  841. if (action == Ext.data.Record.EDIT &amp;&amp; this.autoSave === true &amp;&amp; (!record.phantom || (record.phantom &amp;&amp; record.isValid()))) {
  842. this.save();
  843. }
  844. },
  845. <span id='Ext-data-Store-method-createRecords'> /**
  846. </span> * @private
  847. * Should not be used directly. Store#add will call this automatically if a Writer is set
  848. * @param {Object} store
  849. * @param {Object} records
  850. * @param {Object} index
  851. */
  852. createRecords : function(store, records, index) {
  853. var modified = this.modified,
  854. length = records.length,
  855. record, i;
  856. for (i = 0; i &lt; length; i++) {
  857. record = records[i];
  858. if (record.phantom &amp;&amp; record.isValid()) {
  859. record.markDirty(); // &lt;-- Mark new records dirty (Ed: why?)
  860. if (modified.indexOf(record) == -1) {
  861. modified.push(record);
  862. }
  863. }
  864. }
  865. if (this.autoSave === true) {
  866. this.save();
  867. }
  868. },
  869. <span id='Ext-data-Store-method-destroyRecord'> /**
  870. </span> * Destroys a Record. Should not be used directly. It's called by Store#remove if a Writer is set.
  871. * @param {Store} store this
  872. * @param {Ext.data.Record} record
  873. * @param {Number} index
  874. * @private
  875. */
  876. destroyRecord : function(store, record, index) {
  877. if (this.modified.indexOf(record) != -1) { // &lt;-- handled already if @cfg pruneModifiedRecords == true
  878. this.modified.remove(record);
  879. }
  880. if (!record.phantom) {
  881. this.removed.push(record);
  882. // since the record has already been removed from the store but the server request has not yet been executed,
  883. // must keep track of the last known index this record existed. If a server error occurs, the record can be
  884. // put back into the store. @see Store#createCallback where the record is returned when response status === false
  885. record.lastIndex = index;
  886. if (this.autoSave === true) {
  887. this.save();
  888. }
  889. }
  890. },
  891. <span id='Ext-data-Store-method-execute'> /**
  892. </span> * This method should generally not be used directly. This method is called internally
  893. * by {@link #load}, or if a Writer is set will be called automatically when {@link #add},
  894. * {@link #remove}, or {@link #update} events fire.
  895. * @param {String} action Action name ('read', 'create', 'update', or 'destroy')
  896. * @param {Record/Record[]} rs
  897. * @param {Object} options
  898. * @throws Error
  899. * @private
  900. */
  901. execute : function(action, rs, options, /* private */ batch) {
  902. // blow up if action not Ext.data.CREATE, READ, UPDATE, DESTROY
  903. if (!Ext.data.Api.isAction(action)) {
  904. throw new Ext.data.Api.Error('execute', action);
  905. }
  906. // make sure options has a fresh, new params hash
  907. options = Ext.applyIf(options||{}, {
  908. params: {}
  909. });
  910. if(batch !== undefined){
  911. this.addToBatch(batch);
  912. }
  913. // have to separate before-events since load has a different signature than create,destroy and save events since load does not
  914. // include the rs (record resultset) parameter. Capture return values from the beforeaction into doRequest flag.
  915. var doRequest = true;
  916. if (action === 'read') {
  917. doRequest = this.fireEvent('beforeload', this, options);
  918. Ext.applyIf(options.params, this.baseParams);
  919. }
  920. else {
  921. // if Writer is configured as listful, force single-record rs to be [{}] instead of {}
  922. // TODO Move listful rendering into DataWriter where the @cfg is defined. Should be easy now.
  923. if (this.writer.listful === true &amp;&amp; this.restful !== true) {
  924. rs = (Ext.isArray(rs)) ? rs : [rs];
  925. }
  926. // if rs has just a single record, shift it off so that Writer writes data as '{}' rather than '[{}]'
  927. else if (Ext.isArray(rs) &amp;&amp; rs.length == 1) {
  928. rs = rs.shift();
  929. }
  930. // Write the action to options.params
  931. if ((doRequest = this.fireEvent('beforewrite', this, action, rs, options)) !== false) {
  932. this.writer.apply(options.params, this.baseParams, action, rs);
  933. }
  934. }
  935. if (doRequest !== false) {
  936. // Send request to proxy.
  937. if (this.writer &amp;&amp; this.proxy.url &amp;&amp; !this.proxy.restful &amp;&amp; !Ext.data.Api.hasUniqueUrl(this.proxy, action)) {
  938. options.params.xaction = action; // &lt;-- really old, probaby unecessary.
  939. }
  940. // Note: Up until this point we've been dealing with 'action' as a key from Ext.data.Api.actions.
  941. // We'll flip it now and send the value into DataProxy#request, since it's the value which maps to
  942. // the user's configured DataProxy#api
  943. // TODO Refactor all Proxies to accept an instance of Ext.data.Request (not yet defined) instead of this looooooong list
  944. // of params. This method is an artifact from Ext2.
  945. this.proxy.request(Ext.data.Api.actions[action], rs, options.params, this.reader, this.createCallback(action, rs, batch), this, options);
  946. }
  947. return doRequest;
  948. },
  949. <span id='Ext-data-Store-method-save'> /**
  950. </span> * Saves all pending changes to the store. If the commensurate Ext.data.Api.actions action is not configured, then
  951. * the configured &lt;code&gt;{@link #url}&lt;/code&gt; will be used.
  952. * &lt;pre&gt;
  953. * change url
  954. * --------------- --------------------
  955. * removed records Ext.data.Api.actions.destroy
  956. * phantom records Ext.data.Api.actions.create
  957. * {@link #getModifiedRecords modified records} Ext.data.Api.actions.update
  958. * &lt;/pre&gt;
  959. * @TODO: Create extensions of Error class and send associated Record with thrown exceptions.
  960. * e.g.: Ext.data.DataReader.Error or Ext.data.Error or Ext.data.DataProxy.Error, etc.
  961. * @return {Number} batch Returns a number to uniquely identify the &quot;batch&quot; of saves occurring. -1 will be returned
  962. * if there are no items to save or the save was cancelled.
  963. */
  964. save : function() {
  965. if (!this.writer) {
  966. throw new Ext.data.Store.Error('writer-undefined');
  967. }
  968. var queue = [],
  969. len,
  970. trans,
  971. batch,
  972. data = {},
  973. i;
  974. // DESTROY: First check for removed records. Records in this.removed are guaranteed non-phantoms. @see Store#remove
  975. if(this.removed.length){
  976. queue.push(['destroy', this.removed]);
  977. }
  978. // Check for modified records. Use a copy so Store#rejectChanges will work if server returns error.
  979. var rs = [].concat(this.getModifiedRecords());
  980. if(rs.length){
  981. // CREATE: Next check for phantoms within rs. splice-off and execute create.
  982. var phantoms = [];
  983. for(i = rs.length-1; i &gt;= 0; i--){
  984. if(rs[i].phantom === true){
  985. var rec = rs.splice(i, 1).shift();
  986. if(rec.isValid()){
  987. phantoms.push(rec);
  988. }
  989. }else if(!rs[i].isValid()){ // &lt;-- while we're here, splice-off any !isValid real records
  990. rs.splice(i,1);
  991. }
  992. }
  993. // If we have valid phantoms, create them...
  994. if(phantoms.length){
  995. queue.push(['create', phantoms]);
  996. }
  997. // UPDATE: And finally, if we're still here after splicing-off phantoms and !isValid real records, update the rest...
  998. if(rs.length){
  999. queue.push(['update', rs]);
  1000. }
  1001. }
  1002. len = queue.length;
  1003. if(len){
  1004. batch = ++this.batchCounter;
  1005. for(i = 0; i &lt; len; ++i){
  1006. trans = queue[i];
  1007. data[trans[0]] = trans[1];
  1008. }
  1009. if(this.fireEvent('beforesave', this, data) !== false){
  1010. for(i = 0; i &lt; len; ++i){
  1011. trans = queue[i];
  1012. this.doTransaction(trans[0], trans[1], batch);
  1013. }
  1014. return batch;
  1015. }
  1016. }
  1017. return -1;
  1018. },
  1019. <span id='Ext-data-Store-method-doTransaction'> // private. Simply wraps call to Store#execute in try/catch. Defers to Store#handleException on error. Loops if batch: false
  1020. </span> doTransaction : function(action, rs, batch) {
  1021. function transaction(records) {
  1022. try{
  1023. this.execute(action, records, undefined, batch);
  1024. }catch (e){
  1025. this.handleException(e);
  1026. }
  1027. }
  1028. if(this.batch === false){
  1029. for(var i = 0, len = rs.length; i &lt; len; i++){
  1030. transaction.call(this, rs[i]);
  1031. }
  1032. }else{
  1033. transaction.call(this, rs);
  1034. }
  1035. },
  1036. <span id='Ext-data-Store-method-addToBatch'> // private
  1037. </span> addToBatch : function(batch){
  1038. var b = this.batches,
  1039. key = this.batchKey + batch,
  1040. o = b[key];
  1041. if(!o){
  1042. b[key] = o = {
  1043. id: batch,
  1044. count: 0,
  1045. data: {}
  1046. };
  1047. }
  1048. ++o.count;
  1049. },
  1050. <span id='Ext-data-Store-method-removeFromBatch'> removeFromBatch : function(batch, action, data){
  1051. </span> var b = this.batches,
  1052. key = this.batchKey + batch,
  1053. o = b[key],
  1054. arr;
  1055. if(o){
  1056. arr = o.data[action] || [];
  1057. o.data[action] = arr.concat(data);
  1058. if(o.count === 1){
  1059. data = o.data;
  1060. delete b[key];
  1061. this.fireEvent('save', this, batch, data);
  1062. }else{
  1063. --o.count;
  1064. }
  1065. }
  1066. },
  1067. <span id='Ext-data-Store-method-createCallback'> // @private callback-handler for remote CRUD actions
  1068. </span> // Do not override -- override loadRecords, onCreateRecords, onDestroyRecords and onUpdateRecords instead.
  1069. createCallback : function(action, rs, batch) {
  1070. var actions = Ext.data.Api.actions;
  1071. return (action == 'read') ? this.loadRecords : function(data, response, success) {
  1072. // calls: onCreateRecords | onUpdateRecords | onDestroyRecords
  1073. this['on' + Ext.util.Format.capitalize(action) + 'Records'](success, rs, [].concat(data));
  1074. // If success === false here, exception will have been called in DataProxy
  1075. if (success === true) {
  1076. this.fireEvent('write', this, action, data, response, rs);
  1077. }
  1078. this.removeFromBatch(batch, action, data);
  1079. };
  1080. },
  1081. <span id='Ext-data-Store-method-clearModified'> // Clears records from modified array after an exception event.
  1082. </span> // NOTE: records are left marked dirty. Do we want to commit them even though they were not updated/realized?
  1083. // TODO remove this method?
  1084. clearModified : function(rs) {
  1085. if (Ext.isArray(rs)) {
  1086. for (var n=rs.length-1;n&gt;=0;n--) {
  1087. this.modified.splice(this.modified.indexOf(rs[n]), 1);
  1088. }
  1089. } else {
  1090. this.modified.splice(this.modified.indexOf(rs), 1);
  1091. }
  1092. },
  1093. <span id='Ext-data-Store-method-reMap'> // remap record ids in MixedCollection after records have been realized. @see Store#onCreateRecords, @see DataReader#realize
  1094. </span> reMap : function(record) {
  1095. if (Ext.isArray(record)) {
  1096. for (var i = 0, len = record.length; i &lt; len; i++) {
  1097. this.reMap(record[i]);
  1098. }
  1099. } else {
  1100. delete this.data.map[record._phid];
  1101. this.data.map[record.id] = record;
  1102. var index = this.data.keys.indexOf(record._phid);
  1103. this.data.keys.splice(index, 1, record.id);
  1104. delete record._phid;
  1105. }
  1106. },
  1107. <span id='Ext-data-Store-method-onCreateRecords'> // @protected onCreateRecord proxy callback for create action
  1108. </span> onCreateRecords : function(success, rs, data) {
  1109. if (success === true) {
  1110. try {
  1111. this.reader.realize(rs, data);
  1112. }
  1113. catch (e) {
  1114. this.handleException(e);
  1115. if (Ext.isArray(rs)) {
  1116. // Recurse to run back into the try {}. DataReader#realize splices-off the rs until empty.
  1117. this.onCreateRecords(success, rs, data);
  1118. }
  1119. }
  1120. }
  1121. },
  1122. <span id='Ext-data-Store-method-onUpdateRecords'> // @protected, onUpdateRecords proxy callback for update action
  1123. </span> onUpdateRecords : function(success, rs, data) {
  1124. if (success === true) {
  1125. try {
  1126. this.reader.update(rs, data);
  1127. } catch (e) {
  1128. this.handleException(e);
  1129. if (Ext.isArray(rs)) {
  1130. // Recurse to run back into the try {}. DataReader#update splices-off the rs until empty.
  1131. this.onUpdateRecords(success, rs, data);
  1132. }
  1133. }
  1134. }
  1135. },
  1136. <span id='Ext-data-Store-method-onDestroyRecords'> // @protected onDestroyRecords proxy callback for destroy action
  1137. </span> onDestroyRecords : function(success, rs, data) {
  1138. // splice each rec out of this.removed
  1139. rs = (rs instanceof Ext.data.Record) ? [rs] : [].concat(rs);
  1140. for (var i=0,len=rs.length;i&lt;len;i++) {
  1141. this.removed.splice(this.removed.indexOf(rs[i]), 1);
  1142. }
  1143. if (success === false) {
  1144. // put records back into store if remote destroy fails.
  1145. // @TODO: Might want to let developer decide.
  1146. for (i=rs.length-1;i&gt;=0;i--) {
  1147. this.insert(rs[i].lastIndex, rs[i]); // &lt;-- lastIndex set in Store#destroyRecord
  1148. }
  1149. }
  1150. },
  1151. <span id='Ext-data-Store-method-handleException'> // protected handleException. Possibly temporary until Ext framework has an exception-handler.
  1152. </span> handleException : function(e) {
  1153. // @see core/Error.js
  1154. Ext.handleError(e);
  1155. },
  1156. <span id='Ext-data-Store-method-reload'> /**
  1157. </span> * &lt;p&gt;Reloads the Record cache from the configured Proxy using the configured
  1158. * {@link Ext.data.Reader Reader} and the options from the last load operation
  1159. * performed.&lt;/p&gt;
  1160. * &lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: see the Important note in {@link #load}.&lt;/p&gt;
  1161. * @param {Object} options &lt;p&gt;(optional) An &lt;tt&gt;Object&lt;/tt&gt; containing
  1162. * {@link #load loading options} which may override the {@link #lastOptions options}
  1163. * used in the last {@link #load} operation. See {@link #load} for details
  1164. * (defaults to &lt;tt&gt;null&lt;/tt&gt;, in which case the {@link #lastOptions} are
  1165. * used).&lt;/p&gt;
  1166. * &lt;br&gt;&lt;p&gt;To add new params to the existing params:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  1167. lastOptions = myStore.lastOptions;
  1168. Ext.apply(lastOptions.params, {
  1169. myNewParam: true
  1170. });
  1171. myStore.reload(lastOptions);
  1172. * &lt;/code&gt;&lt;/pre&gt;
  1173. */
  1174. reload : function(options){
  1175. this.load(Ext.applyIf(options||{}, this.lastOptions));
  1176. },
  1177. <span id='Ext-data-Store-method-loadRecords'> // private
  1178. </span> // Called as a callback by the Reader during a load operation.
  1179. loadRecords : function(o, options, success){
  1180. var i, len;
  1181. if (this.isDestroyed === true) {
  1182. return;
  1183. }
  1184. if(!o || success === false){
  1185. if(success !== false){
  1186. this.fireEvent('load', this, [], options);
  1187. }
  1188. if(options.callback){
  1189. options.callback.call(options.scope || this, [], options, false, o);
  1190. }
  1191. return;
  1192. }
  1193. var r = o.records, t = o.totalRecords || r.length;
  1194. if(!options || options.add !== true){
  1195. if(this.pruneModifiedRecords){
  1196. this.modified = [];
  1197. }
  1198. for(i = 0, len = r.length; i &lt; len; i++){
  1199. r[i].join(this);
  1200. }
  1201. if(this.snapshot){
  1202. this.data = this.snapshot;
  1203. delete this.snapshot;
  1204. }
  1205. this.clearData();
  1206. this.data.addAll(r);
  1207. this.totalLength = t;
  1208. this.applySort();
  1209. this.fireEvent('datachanged', this);
  1210. }else{
  1211. var toAdd = [],
  1212. rec,
  1213. cnt = 0;
  1214. for(i = 0, len = r.length; i &lt; len; ++i){
  1215. rec = r[i];
  1216. if(this.indexOfId(rec.id) &gt; -1){
  1217. this.doUpdate(rec);
  1218. }else{
  1219. toAdd.push(rec);
  1220. ++cnt;
  1221. }
  1222. }
  1223. this.totalLength = Math.max(t, this.data.length + cnt);
  1224. this.add(toAdd);
  1225. }
  1226. this.fireEvent('load', this, r, options);
  1227. if(options.callback){
  1228. options.callback.call(options.scope || this, r, options, true);
  1229. }
  1230. },
  1231. <span id='Ext-data-Store-method-loadData'> /**
  1232. </span> * Loads data from a passed data block and fires the {@link #load} event. A {@link Ext.data.Reader Reader}
  1233. * which understands the format of the data must have been configured in the constructor.
  1234. * @param {Object} data The data block from which to read the Records. The format of the data expected
  1235. * is dependent on the type of {@link Ext.data.Reader Reader} that is configured and should correspond to
  1236. * that {@link Ext.data.Reader Reader}'s &lt;tt&gt;{@link Ext.data.Reader#readRecords}&lt;/tt&gt; parameter.
  1237. * @param {Boolean} append (Optional) &lt;tt&gt;true&lt;/tt&gt; to append the new Records rather the default to replace
  1238. * the existing cache.
  1239. * &lt;b&gt;Note&lt;/b&gt;: that Records in a Store are keyed by their {@link Ext.data.Record#id id}, so added Records
  1240. * with ids which are already present in the Store will &lt;i&gt;replace&lt;/i&gt; existing Records. Only Records with
  1241. * new, unique ids will be added.
  1242. */
  1243. loadData : function(o, append){
  1244. var r = this.reader.readRecords(o);
  1245. this.loadRecords(r, {add: append}, true);
  1246. },
  1247. <span id='Ext-data-Store-method-getCount'> /**
  1248. </span> * Gets the number of cached records.
  1249. * &lt;p&gt;If using paging, this may not be the total size of the dataset. If the data object
  1250. * used by the Reader contains the dataset size, then the {@link #getTotalCount} function returns
  1251. * the dataset size. &lt;b&gt;Note&lt;/b&gt;: see the Important note in {@link #load}.&lt;/p&gt;
  1252. * @return {Number} The number of Records in the Store's cache.
  1253. */
  1254. getCount : function(){
  1255. return this.data.length || 0;
  1256. },
  1257. <span id='Ext-data-Store-method-getTotalCount'> /**
  1258. </span> * Gets the total number of records in the dataset as returned by the server.
  1259. * &lt;p&gt;If using paging, for this to be accurate, the data object used by the {@link #reader Reader}
  1260. * must contain the dataset size. For remote data sources, the value for this property
  1261. * (&lt;tt&gt;totalProperty&lt;/tt&gt; for {@link Ext.data.JsonReader JsonReader},
  1262. * &lt;tt&gt;totalRecords&lt;/tt&gt; for {@link Ext.data.XmlReader XmlReader}) shall be returned by a query on the server.
  1263. * &lt;b&gt;Note&lt;/b&gt;: see the Important note in {@link #load}.&lt;/p&gt;
  1264. * @return {Number} The number of Records as specified in the data object passed to the Reader
  1265. * by the Proxy.
  1266. * &lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: this value is not updated when changing the contents of the Store locally.&lt;/p&gt;
  1267. */
  1268. getTotalCount : function(){
  1269. return this.totalLength || 0;
  1270. },
  1271. <span id='Ext-data-Store-method-getSortState'> /**
  1272. </span> * Returns an object describing the current sort state of this Store.
  1273. * @return {Object} The sort state of the Store. An object with two properties:&lt;ul&gt;
  1274. * &lt;li&gt;&lt;b&gt;field : String&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;The name of the field by which the Records are sorted.&lt;/p&gt;&lt;/li&gt;
  1275. * &lt;li&gt;&lt;b&gt;direction : String&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;The sort order, 'ASC' or 'DESC' (case-sensitive).&lt;/p&gt;&lt;/li&gt;
  1276. * &lt;/ul&gt;
  1277. * See &lt;tt&gt;{@link #sortInfo}&lt;/tt&gt; for additional details.
  1278. */
  1279. getSortState : function(){
  1280. return this.sortInfo;
  1281. },
  1282. <span id='Ext-data-Store-method-applySort'> /**
  1283. </span> * @private
  1284. * Invokes sortData if we have sortInfo to sort on and are not sorting remotely
  1285. */
  1286. applySort : function(){
  1287. if ((this.sortInfo || this.multiSortInfo) &amp;&amp; !this.remoteSort) {
  1288. this.sortData();
  1289. }
  1290. },
  1291. <span id='Ext-data-Store-method-sortData'> /**
  1292. </span> * @private
  1293. * Performs the actual sorting of data. This checks to see if we currently have a multi sort or not. It applies
  1294. * each sorter field/direction pair in turn by building an OR'ed master sorting function and running it against
  1295. * the full dataset
  1296. */
  1297. sortData : function() {
  1298. var sortInfo = this.hasMultiSort ? this.multiSortInfo : this.sortInfo,
  1299. direction = sortInfo.direction || &quot;ASC&quot;,
  1300. sorters = sortInfo.sorters,
  1301. sortFns = [];
  1302. //if we just have a single sorter, pretend it's the first in an array
  1303. if (!this.hasMultiSort) {
  1304. sorters = [{direction: direction, field: sortInfo.field}];
  1305. }
  1306. //create a sorter function for each sorter field/direction combo
  1307. for (var i=0, j = sorters.length; i &lt; j; i++) {
  1308. sortFns.push(this.createSortFunction(sorters[i].field, sorters[i].direction));
  1309. }
  1310. if (sortFns.length == 0) {
  1311. return;
  1312. }
  1313. //the direction modifier is multiplied with the result of the sorting functions to provide overall sort direction
  1314. //(as opposed to direction per field)
  1315. var directionModifier = direction.toUpperCase() == &quot;DESC&quot; ? -1 : 1;
  1316. //create a function which ORs each sorter together to enable multi-sort
  1317. var fn = function(r1, r2) {
  1318. var result = sortFns[0].call(this, r1, r2);
  1319. //if we have more than one sorter, OR any additional sorter functions together
  1320. if (sortFns.length &gt; 1) {
  1321. for (var i=1, j = sortFns.length; i &lt; j; i++) {
  1322. result = result || sortFns[i].call(this, r1, r2);
  1323. }
  1324. }
  1325. return directionModifier * result;
  1326. };
  1327. //sort the data
  1328. this.data.sort(direction, fn);
  1329. if (this.snapshot &amp;&amp; this.snapshot != this.data) {
  1330. this.snapshot.sort(direction, fn);
  1331. }
  1332. },
  1333. <span id='Ext-data-Store-method-createSortFunction'> /**
  1334. </span> * @private
  1335. * Creates and returns a function which sorts an array by the given field and direction
  1336. * @param {String} field The field to create the sorter for
  1337. * @param {String} direction The direction to sort by (defaults to &quot;ASC&quot;)
  1338. * @return {Function} A function which sorts by the field/direction combination provided
  1339. */
  1340. createSortFunction: function(field, direction) {
  1341. direction = direction || &quot;ASC&quot;;
  1342. var directionModifier = direction.toUpperCase() == &quot;DESC&quot; ? -1 : 1;
  1343. var sortType = this.fields.get(field).sortType;
  1344. //create a comparison function. Takes 2 records, returns 1 if record 1 is greater,
  1345. //-1 if record 2 is greater or 0 if they are equal
  1346. return function(r1, r2) {
  1347. var v1 = sortType(r1.data[field]),
  1348. v2 = sortType(r2.data[field]);
  1349. return directionModifier * (v1 &gt; v2 ? 1 : (v1 &lt; v2 ? -1 : 0));
  1350. };
  1351. },
  1352. <span id='Ext-data-Store-method-setDefaultSort'> /**
  1353. </span> * Sets the default sort column and order to be used by the next {@link #load} operation.
  1354. * @param {String} fieldName The name of the field to sort by.
  1355. * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to &lt;tt&gt;'ASC'&lt;/tt&gt;)
  1356. */
  1357. setDefaultSort : function(field, dir) {
  1358. dir = dir ? dir.toUpperCase() : 'ASC';
  1359. this.sortInfo = {field: field, direction: dir};
  1360. this.sortToggle[field] = dir;
  1361. },
  1362. <span id='Ext-data-Store-method-sort'> /**
  1363. </span> * Sort the Records.
  1364. * If remote sorting is used, the sort is performed on the server, and the cache is reloaded. If local
  1365. * sorting is used, the cache is sorted internally. See also {@link #remoteSort} and {@link #paramNames}.
  1366. * This function accepts two call signatures - pass in a field name as the first argument to sort on a single
  1367. * field, or pass in an array of sort configuration objects to sort by multiple fields.
  1368. * Single sort example:
  1369. * store.sort('name', 'ASC');
  1370. * Multi sort example:
  1371. * store.sort([
  1372. * {
  1373. * field : 'name',
  1374. * direction: 'ASC'
  1375. * },
  1376. * {
  1377. * field : 'salary',
  1378. * direction: 'DESC'
  1379. * }
  1380. * ], 'ASC');
  1381. * In this second form, the sort configs are applied in order, with later sorters sorting within earlier sorters' results.
  1382. * For example, if two records with the same name are present they will also be sorted by salary if given the sort configs
  1383. * above. Any number of sort configs can be added.
  1384. * @param {String/Array} fieldName The name of the field to sort by, or an array of ordered sort configs
  1385. * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to &lt;tt&gt;'ASC'&lt;/tt&gt;)
  1386. */
  1387. sort : function(fieldName, dir) {
  1388. if (Ext.isArray(arguments[0])) {
  1389. return this.multiSort.call(this, fieldName, dir);
  1390. } else {
  1391. return this.singleSort(fieldName, dir);
  1392. }
  1393. },
  1394. <span id='Ext-data-Store-method-singleSort'> /**
  1395. </span> * Sorts the store contents by a single field and direction. This is called internally by {@link sort} and would
  1396. * not usually be called manually
  1397. * @param {String} fieldName The name of the field to sort by.
  1398. * @param {String} dir (optional) The sort order, 'ASC' or 'DESC' (case-sensitive, defaults to &lt;tt&gt;'ASC'&lt;/tt&gt;)
  1399. */
  1400. singleSort: function(fieldName, dir) {
  1401. var field = this.fields.get(fieldName);
  1402. if (!field) {
  1403. return false;
  1404. }
  1405. var name = field.name,
  1406. sortInfo = this.sortInfo || null,
  1407. sortToggle = this.sortToggle ? this.sortToggle[name] : null;
  1408. if (!dir) {
  1409. if (sortInfo &amp;&amp; sortInfo.field == name) { // toggle sort dir
  1410. dir = (this.sortToggle[name] || 'ASC').toggle('ASC', 'DESC');
  1411. } else {
  1412. dir = field.sortDir;
  1413. }
  1414. }
  1415. this.sortToggle[name] = dir;
  1416. this.sortInfo = {field: name, direction: dir};
  1417. this.hasMultiSort = false;
  1418. if (this.remoteSort) {
  1419. if (!this.load(this.lastOptions)) {
  1420. if (sortToggle) {
  1421. this.sortToggle[name] = sortToggle;
  1422. }
  1423. if (sortInfo) {
  1424. this.sortInfo = sortInfo;
  1425. }
  1426. }
  1427. } else {
  1428. this.applySort();
  1429. this.fireEvent('datachanged', this);
  1430. }
  1431. return true;
  1432. },
  1433. <span id='Ext-data-Store-method-multiSort'> /**
  1434. </span> * Sorts the contents of this store by multiple field/direction sorters. This is called internally by {@link sort}
  1435. * and would not usually be called manually.
  1436. * Multi sorting only currently applies to local datasets - multiple sort data is not currently sent to a proxy
  1437. * if remoteSort is used.
  1438. * @param {Array} sorters Array of sorter objects (field and direction)
  1439. * @param {String} direction Overall direction to sort the ordered results by (defaults to &quot;ASC&quot;)
  1440. */
  1441. multiSort: function(sorters, direction) {
  1442. this.hasMultiSort = true;
  1443. direction = direction || &quot;ASC&quot;;
  1444. //toggle sort direction
  1445. if (this.multiSortInfo &amp;&amp; direction == this.multiSortInfo.direction) {
  1446. direction = direction.toggle(&quot;ASC&quot;, &quot;DESC&quot;);
  1447. }
  1448. <span id='Ext-data-Store-property-multiSortInfo'> /**
  1449. </span> * Object containing overall sort direction and an ordered array of sorter configs used when sorting on multiple fields
  1450. * @property multiSortInfo
  1451. * @type Object
  1452. */
  1453. this.multiSortInfo = {
  1454. sorters : sorters,
  1455. direction: direction
  1456. };
  1457. if (this.remoteSort) {
  1458. this.singleSort(sorters[0].field, sorters[0].direction);
  1459. } else {
  1460. this.applySort();
  1461. this.fireEvent('datachanged', this);
  1462. }
  1463. },
  1464. <span id='Ext-data-Store-method-each'> /**
  1465. </span> * Calls the specified function for each of the {@link Ext.data.Record Records} in the cache.
  1466. * @param {Function} fn The function to call. The {@link Ext.data.Record Record} is passed as the first parameter.
  1467. * Returning &lt;tt&gt;false&lt;/tt&gt; aborts and exits the iteration.
  1468. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed.
  1469. * Defaults to the current {@link Ext.data.Record Record} in the iteration.
  1470. */
  1471. each : function(fn, scope){
  1472. this.data.each(fn, scope);
  1473. },
  1474. <span id='Ext-data-Store-method-getModifiedRecords'> /**
  1475. </span> * Gets all {@link Ext.data.Record records} modified since the last commit. Modified records are
  1476. * persisted across load operations (e.g., during paging). &lt;b&gt;Note&lt;/b&gt;: deleted records are not
  1477. * included. See also &lt;tt&gt;{@link #pruneModifiedRecords}&lt;/tt&gt; and
  1478. * {@link Ext.data.Record}&lt;tt&gt;{@link Ext.data.Record#markDirty markDirty}.&lt;/tt&gt;.
  1479. * @return {Ext.data.Record[]} An array of {@link Ext.data.Record Records} containing outstanding
  1480. * modifications. To obtain modified fields within a modified record see
  1481. *{@link Ext.data.Record}&lt;tt&gt;{@link Ext.data.Record#modified modified}.&lt;/tt&gt;.
  1482. */
  1483. getModifiedRecords : function(){
  1484. return this.modified;
  1485. },
  1486. <span id='Ext-data-Store-method-sum'> /**
  1487. </span> * Sums the value of &lt;tt&gt;property&lt;/tt&gt; for each {@link Ext.data.Record record} between &lt;tt&gt;start&lt;/tt&gt;
  1488. * and &lt;tt&gt;end&lt;/tt&gt; and returns the result.
  1489. * @param {String} property A field in each record
  1490. * @param {Number} start (optional) The record index to start at (defaults to &lt;tt&gt;0&lt;/tt&gt;)
  1491. * @param {Number} end (optional) The last record index to include (defaults to length - 1)
  1492. * @return {Number} The sum
  1493. */
  1494. sum : function(property, start, end){
  1495. var rs = this.data.items, v = 0;
  1496. start = start || 0;
  1497. end = (end || end === 0) ? end : rs.length-1;
  1498. for(var i = start; i &lt;= end; i++){
  1499. v += (rs[i].data[property] || 0);
  1500. }
  1501. return v;
  1502. },
  1503. <span id='Ext-data-Store-method-createFilterFn'> /**
  1504. </span> * @private
  1505. * Returns a filter function used to test a the given property's value. Defers most of the work to
  1506. * Ext.util.MixedCollection's createValueMatcher function
  1507. * @param {String} property The property to create the filter function for
  1508. * @param {String/RegExp} value The string/regex to compare the property value to
  1509. * @param {Boolean} anyMatch True if we don't care if the filter value is not the full value (defaults to false)
  1510. * @param {Boolean} caseSensitive True to create a case-sensitive regex (defaults to false)
  1511. * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
  1512. */
  1513. createFilterFn : function(property, value, anyMatch, caseSensitive, exactMatch){
  1514. if(Ext.isEmpty(value, false)){
  1515. return false;
  1516. }
  1517. value = this.data.createValueMatcher(value, anyMatch, caseSensitive, exactMatch);
  1518. return function(r) {
  1519. return value.test(r.data[property]);
  1520. };
  1521. },
  1522. <span id='Ext-data-Store-method-createMultipleFilterFn'> /**
  1523. </span> * @private
  1524. * Given an array of filter functions (each with optional scope), constructs and returns a single function that returns
  1525. * the result of all of the filters ANDed together
  1526. * @param {Array} filters The array of filter objects (each object should contain an 'fn' and optional scope)
  1527. * @return {Function} The multiple filter function
  1528. */
  1529. createMultipleFilterFn: function(filters) {
  1530. return function(record) {
  1531. var isMatch = true;
  1532. for (var i=0, j = filters.length; i &lt; j; i++) {
  1533. var filter = filters[i],
  1534. fn = filter.fn,
  1535. scope = filter.scope;
  1536. isMatch = isMatch &amp;&amp; fn.call(scope, record);
  1537. }
  1538. return isMatch;
  1539. };
  1540. },
  1541. <span id='Ext-data-Store-method-filter'> /**
  1542. </span> * Filter the {@link Ext.data.Record records} by a specified property. Alternatively, pass an array of filter
  1543. * options to filter by more than one property.
  1544. * Single filter example:
  1545. * store.filter('name', 'Ed', true, true); //finds all records containing the substring 'Ed'
  1546. * Multiple filter example:
  1547. * &lt;pre&gt;&lt;code&gt;
  1548. * store.filter([
  1549. * {
  1550. * property : 'name',
  1551. * value : 'Ed',
  1552. * anyMatch : true, //optional, defaults to true
  1553. * caseSensitive: true //optional, defaults to true
  1554. * },
  1555. *
  1556. * //filter functions can also be passed
  1557. * {
  1558. * fn : function(record) {
  1559. * return record.get('age') == 24
  1560. * },
  1561. * scope: this
  1562. * }
  1563. * ]);
  1564. * &lt;/code&gt;&lt;/pre&gt;
  1565. * @param {String|Array} field A field on your records, or an array containing multiple filter options
  1566. * @param {String/RegExp} value Either a string that the field should begin with, or a RegExp to test
  1567. * against the field.
  1568. * @param {Boolean} anyMatch (optional) &lt;tt&gt;true&lt;/tt&gt; to match any part not just the beginning
  1569. * @param {Boolean} caseSensitive (optional) &lt;tt&gt;true&lt;/tt&gt; for case sensitive comparison
  1570. * @param {Boolean} exactMatch (optional) True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
  1571. */
  1572. filter : function(property, value, anyMatch, caseSensitive, exactMatch){
  1573. var fn;
  1574. //we can accept an array of filter objects, or a single filter object - normalize them here
  1575. if (Ext.isObject(property)) {
  1576. property = [property];
  1577. }
  1578. if (Ext.isArray(property)) {
  1579. var filters = [];
  1580. //normalize the filters passed into an array of filter functions
  1581. for (var i=0, j = property.length; i &lt; j; i++) {
  1582. var filter = property[i],
  1583. func = filter.fn,
  1584. scope = filter.scope || this;
  1585. //if we weren't given a filter function, construct one now
  1586. if (!Ext.isFunction(func)) {
  1587. func = this.createFilterFn(filter.property, filter.value, filter.anyMatch, filter.caseSensitive, filter.exactMatch);
  1588. }
  1589. filters.push({fn: func, scope: scope});
  1590. }
  1591. fn = this.createMultipleFilterFn(filters);
  1592. } else {
  1593. //classic single property filter
  1594. fn = this.createFilterFn(property, value, anyMatch, caseSensitive, exactMatch);
  1595. }
  1596. return fn ? this.filterBy(fn) : this.clearFilter();
  1597. },
  1598. <span id='Ext-data-Store-method-filterBy'> /**
  1599. </span> * Filter by a function. The specified function will be called for each
  1600. * Record in this Store. If the function returns &lt;tt&gt;true&lt;/tt&gt; the Record is included,
  1601. * otherwise it is filtered out.
  1602. * @param {Function} fn The function to be called. It will be passed the following parameters:&lt;ul&gt;
  1603. * &lt;li&gt;&lt;b&gt;record&lt;/b&gt; : Ext.data.Record&lt;p class=&quot;sub-desc&quot;&gt;The {@link Ext.data.Record record}
  1604. * to test for filtering. Access field values using {@link Ext.data.Record#get}.&lt;/p&gt;&lt;/li&gt;
  1605. * &lt;li&gt;&lt;b&gt;id&lt;/b&gt; : Object&lt;p class=&quot;sub-desc&quot;&gt;The ID of the Record passed.&lt;/p&gt;&lt;/li&gt;
  1606. * &lt;/ul&gt;
  1607. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed. Defaults to this Store.
  1608. */
  1609. filterBy : function(fn, scope){
  1610. this.snapshot = this.snapshot || this.data;
  1611. this.data = this.queryBy(fn, scope || this);
  1612. this.fireEvent('datachanged', this);
  1613. },
  1614. <span id='Ext-data-Store-method-clearFilter'> /**
  1615. </span> * Revert to a view of the Record cache with no filtering applied.
  1616. * @param {Boolean} suppressEvent If &lt;tt&gt;true&lt;/tt&gt; the filter is cleared silently without firing the
  1617. * {@link #datachanged} event.
  1618. */
  1619. clearFilter : function(suppressEvent){
  1620. if(this.isFiltered()){
  1621. this.data = this.snapshot;
  1622. delete this.snapshot;
  1623. if(suppressEvent !== true){
  1624. this.fireEvent('datachanged', this);
  1625. }
  1626. }
  1627. },
  1628. <span id='Ext-data-Store-method-isFiltered'> /**
  1629. </span> * Returns true if this store is currently filtered
  1630. * @return {Boolean}
  1631. */
  1632. isFiltered : function(){
  1633. return !!this.snapshot &amp;&amp; this.snapshot != this.data;
  1634. },
  1635. <span id='Ext-data-Store-method-query'> /**
  1636. </span> * Query the records by a specified property.
  1637. * @param {String} field A field on your records
  1638. * @param {String/RegExp} value Either a string that the field
  1639. * should begin with, or a RegExp to test against the field.
  1640. * @param {Boolean} anyMatch (optional) True to match any part not just the beginning
  1641. * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
  1642. * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
  1643. */
  1644. query : function(property, value, anyMatch, caseSensitive){
  1645. var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
  1646. return fn ? this.queryBy(fn) : this.data.clone();
  1647. },
  1648. <span id='Ext-data-Store-method-queryBy'> /**
  1649. </span> * Query the cached records in this Store using a filtering function. The specified function
  1650. * will be called with each record in this Store. If the function returns &lt;tt&gt;true&lt;/tt&gt; the record is
  1651. * included in the results.
  1652. * @param {Function} fn The function to be called. It will be passed the following parameters:&lt;ul&gt;
  1653. * &lt;li&gt;&lt;b&gt;record&lt;/b&gt; : Ext.data.Record&lt;p class=&quot;sub-desc&quot;&gt;The {@link Ext.data.Record record}
  1654. * to test for filtering. Access field values using {@link Ext.data.Record#get}.&lt;/p&gt;&lt;/li&gt;
  1655. * &lt;li&gt;&lt;b&gt;id&lt;/b&gt; : Object&lt;p class=&quot;sub-desc&quot;&gt;The ID of the Record passed.&lt;/p&gt;&lt;/li&gt;
  1656. * &lt;/ul&gt;
  1657. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed. Defaults to this Store.
  1658. * @return {MixedCollection} Returns an Ext.util.MixedCollection of the matched records
  1659. **/
  1660. queryBy : function(fn, scope){
  1661. var data = this.snapshot || this.data;
  1662. return data.filterBy(fn, scope||this);
  1663. },
  1664. <span id='Ext-data-Store-method-find'> /**
  1665. </span> * Finds the index of the first matching Record in this store by a specific field value.
  1666. * @param {String} fieldName The name of the Record field to test.
  1667. * @param {String/RegExp} value Either a string that the field value
  1668. * should begin with, or a RegExp to test against the field.
  1669. * @param {Number} startIndex (optional) The index to start searching at
  1670. * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
  1671. * @param {Boolean} caseSensitive (optional) True for case sensitive comparison
  1672. * @return {Number} The matched index or -1
  1673. */
  1674. find : function(property, value, start, anyMatch, caseSensitive){
  1675. var fn = this.createFilterFn(property, value, anyMatch, caseSensitive);
  1676. return fn ? this.data.findIndexBy(fn, null, start) : -1;
  1677. },
  1678. <span id='Ext-data-Store-method-findExact'> /**
  1679. </span> * Finds the index of the first matching Record in this store by a specific field value.
  1680. * @param {String} fieldName The name of the Record field to test.
  1681. * @param {Mixed} value The value to match the field against.
  1682. * @param {Number} startIndex (optional) The index to start searching at
  1683. * @return {Number} The matched index or -1
  1684. */
  1685. findExact: function(property, value, start){
  1686. return this.data.findIndexBy(function(rec){
  1687. return rec.get(property) === value;
  1688. }, this, start);
  1689. },
  1690. <span id='Ext-data-Store-method-findBy'> /**
  1691. </span> * Find the index of the first matching Record in this Store by a function.
  1692. * If the function returns &lt;tt&gt;true&lt;/tt&gt; it is considered a match.
  1693. * @param {Function} fn The function to be called. It will be passed the following parameters:&lt;ul&gt;
  1694. * &lt;li&gt;&lt;b&gt;record&lt;/b&gt; : Ext.data.Record&lt;p class=&quot;sub-desc&quot;&gt;The {@link Ext.data.Record record}
  1695. * to test for filtering. Access field values using {@link Ext.data.Record#get}.&lt;/p&gt;&lt;/li&gt;
  1696. * &lt;li&gt;&lt;b&gt;id&lt;/b&gt; : Object&lt;p class=&quot;sub-desc&quot;&gt;The ID of the Record passed.&lt;/p&gt;&lt;/li&gt;
  1697. * &lt;/ul&gt;
  1698. * @param {Object} scope (optional) The scope (&lt;code&gt;this&lt;/code&gt; reference) in which the function is executed. Defaults to this Store.
  1699. * @param {Number} startIndex (optional) The index to start searching at
  1700. * @return {Number} The matched index or -1
  1701. */
  1702. findBy : function(fn, scope, start){
  1703. return this.data.findIndexBy(fn, scope, start);
  1704. },
  1705. <span id='Ext-data-Store-method-collect'> /**
  1706. </span> * Collects unique values for a particular dataIndex from this store.
  1707. * @param {String} dataIndex The property to collect
  1708. * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
  1709. * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
  1710. * @return {Array} An array of the unique values
  1711. **/
  1712. collect : function(dataIndex, allowNull, bypassFilter){
  1713. var d = (bypassFilter === true &amp;&amp; this.snapshot) ?
  1714. this.snapshot.items : this.data.items;
  1715. var v, sv, r = [], l = {};
  1716. for(var i = 0, len = d.length; i &lt; len; i++){
  1717. v = d[i].data[dataIndex];
  1718. sv = String(v);
  1719. if((allowNull || !Ext.isEmpty(v)) &amp;&amp; !l[sv]){
  1720. l[sv] = true;
  1721. r[r.length] = v;
  1722. }
  1723. }
  1724. return r;
  1725. },
  1726. <span id='Ext-data-Store-method-afterEdit'> // private
  1727. </span> afterEdit : function(record){
  1728. if(this.modified.indexOf(record) == -1){
  1729. this.modified.push(record);
  1730. }
  1731. this.fireEvent('update', this, record, Ext.data.Record.EDIT);
  1732. },
  1733. <span id='Ext-data-Store-method-afterReject'> // private
  1734. </span> afterReject : function(record){
  1735. this.modified.remove(record);
  1736. this.fireEvent('update', this, record, Ext.data.Record.REJECT);
  1737. },
  1738. <span id='Ext-data-Store-method-afterCommit'> // private
  1739. </span> afterCommit : function(record){
  1740. this.modified.remove(record);
  1741. this.fireEvent('update', this, record, Ext.data.Record.COMMIT);
  1742. },
  1743. <span id='Ext-data-Store-method-commitChanges'> /**
  1744. </span> * Commit all Records with {@link #getModifiedRecords outstanding changes}. To handle updates for changes,
  1745. * subscribe to the Store's {@link #update update event}, and perform updating when the third parameter is
  1746. * Ext.data.Record.COMMIT.
  1747. */
  1748. commitChanges : function(){
  1749. var modified = this.modified.slice(0),
  1750. length = modified.length,
  1751. i;
  1752. for (i = 0; i &lt; length; i++){
  1753. modified[i].commit();
  1754. }
  1755. this.modified = [];
  1756. this.removed = [];
  1757. },
  1758. <span id='Ext-data-Store-method-rejectChanges'> /**
  1759. </span> * {@link Ext.data.Record#reject Reject} outstanding changes on all {@link #getModifiedRecords modified records}.
  1760. */
  1761. rejectChanges : function() {
  1762. var modified = this.modified.slice(0),
  1763. removed = this.removed.slice(0).reverse(),
  1764. mLength = modified.length,
  1765. rLength = removed.length,
  1766. i;
  1767. for (i = 0; i &lt; mLength; i++) {
  1768. modified[i].reject();
  1769. }
  1770. for (i = 0; i &lt; rLength; i++) {
  1771. this.insert(removed[i].lastIndex || 0, removed[i]);
  1772. removed[i].reject();
  1773. }
  1774. this.modified = [];
  1775. this.removed = [];
  1776. },
  1777. <span id='Ext-data-Store-method-onMetaChange'> // private
  1778. </span> onMetaChange : function(meta){
  1779. this.recordType = this.reader.recordType;
  1780. this.fields = this.recordType.prototype.fields;
  1781. delete this.snapshot;
  1782. if(this.reader.meta.sortInfo){
  1783. this.sortInfo = this.reader.meta.sortInfo;
  1784. }else if(this.sortInfo &amp;&amp; !this.fields.get(this.sortInfo.field)){
  1785. delete this.sortInfo;
  1786. }
  1787. if(this.writer){
  1788. this.writer.meta = this.reader.meta;
  1789. }
  1790. this.modified = [];
  1791. this.fireEvent('metachange', this, this.reader.meta);
  1792. },
  1793. <span id='Ext-data-Store-method-findInsertIndex'> // private
  1794. </span> findInsertIndex : function(record){
  1795. this.suspendEvents();
  1796. var data = this.data.clone();
  1797. this.data.add(record);
  1798. this.applySort();
  1799. var index = this.data.indexOf(record);
  1800. this.data = data;
  1801. this.resumeEvents();
  1802. return index;
  1803. },
  1804. <span id='Ext-data-Store-method-setBaseParam'> /**
  1805. </span> * Set the value for a property name in this store's {@link #baseParams}. Usage:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  1806. myStore.setBaseParam('foo', {bar:3});
  1807. &lt;/code&gt;&lt;/pre&gt;
  1808. * @param {String} name Name of the property to assign
  1809. * @param {Mixed} value Value to assign the &lt;tt&gt;name&lt;/tt&gt;d property
  1810. **/
  1811. setBaseParam : function (name, value){
  1812. this.baseParams = this.baseParams || {};
  1813. this.baseParams[name] = value;
  1814. }
  1815. });
  1816. Ext.reg('store', Ext.data.Store);
  1817. <span id='Ext-data-Store-Error'>/**
  1818. </span> * @class Ext.data.Store.Error
  1819. * @extends Ext.Error
  1820. * Store Error extension.
  1821. * @param {String} name
  1822. */
  1823. Ext.data.Store.Error = Ext.extend(Ext.Error, {
  1824. <span id='Ext-data-Store-Error-property-name'> name: 'Ext.data.Store'
  1825. </span>});
  1826. Ext.apply(Ext.data.Store.Error.prototype, {
  1827. lang: {
  1828. 'writer-undefined' : 'Attempted to execute a write-action without a DataWriter installed.'
  1829. }
  1830. });
  1831. </pre>
  1832. </body>
  1833. </html>