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.

217 lines
10 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-Field'>/**
  19. </span> * @class Ext.data.Field
  20. * &lt;p&gt;This class encapsulates the field definition information specified in the field definition objects
  21. * passed to {@link Ext.data.Record#create}.&lt;/p&gt;
  22. * &lt;p&gt;Developers do not need to instantiate this class. Instances are created by {@link Ext.data.Record.create}
  23. * and cached in the {@link Ext.data.Record#fields fields} property of the created Record constructor's &lt;b&gt;prototype.&lt;/b&gt;&lt;/p&gt;
  24. */
  25. Ext.data.Field = Ext.extend(Object, {
  26. <span id='Ext-data-Field-method-constructor'> constructor : function(config){
  27. </span> if(Ext.isString(config)){
  28. config = {name: config};
  29. }
  30. Ext.apply(this, config);
  31. var types = Ext.data.Types,
  32. st = this.sortType,
  33. t;
  34. if(this.type){
  35. if(Ext.isString(this.type)){
  36. this.type = Ext.data.Types[this.type.toUpperCase()] || types.AUTO;
  37. }
  38. }else{
  39. this.type = types.AUTO;
  40. }
  41. // named sortTypes are supported, here we look them up
  42. if(Ext.isString(st)){
  43. this.sortType = Ext.data.SortTypes[st];
  44. }else if(Ext.isEmpty(st)){
  45. this.sortType = this.type.sortType;
  46. }
  47. if(!this.convert){
  48. this.convert = this.type.convert;
  49. }
  50. },
  51. <span id='Ext-data-Field-cfg-name'> /**
  52. </span> * @cfg {String} name
  53. * The name by which the field is referenced within the Record. This is referenced by, for example,
  54. * the &lt;code&gt;dataIndex&lt;/code&gt; property in column definition objects passed to {@link Ext.grid.ColumnModel}.
  55. * &lt;p&gt;Note: In the simplest case, if no properties other than &lt;code&gt;name&lt;/code&gt; are required, a field
  56. * definition may consist of just a String for the field name.&lt;/p&gt;
  57. */
  58. <span id='Ext-data-Field-cfg-type'> /**
  59. </span> * @cfg {Mixed} type
  60. * (Optional) The data type for automatic conversion from received data to the &lt;i&gt;stored&lt;/i&gt; value if &lt;code&gt;{@link Ext.data.Field#convert convert}&lt;/code&gt;
  61. * has not been specified. This may be specified as a string value. Possible values are
  62. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  63. * &lt;li&gt;auto (Default, implies no conversion)&lt;/li&gt;
  64. * &lt;li&gt;string&lt;/li&gt;
  65. * &lt;li&gt;int&lt;/li&gt;
  66. * &lt;li&gt;float&lt;/li&gt;
  67. * &lt;li&gt;boolean&lt;/li&gt;
  68. * &lt;li&gt;date&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;
  69. * &lt;p&gt;This may also be specified by referencing a member of the {@link Ext.data.Types} class.&lt;/p&gt;
  70. * &lt;p&gt;Developers may create their own application-specific data types by defining new members of the
  71. * {@link Ext.data.Types} class.&lt;/p&gt;
  72. */
  73. <span id='Ext-data-Field-cfg-convert'> /**
  74. </span> * @cfg {Function} convert
  75. * (Optional) A function which converts the value provided by the Reader into an object that will be stored
  76. * in the Record. It is passed the following parameters:&lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  77. * &lt;li&gt;&lt;b&gt;v&lt;/b&gt; : Mixed&lt;div class=&quot;sub-desc&quot;&gt;The data value as read by the Reader, if undefined will use
  78. * the configured &lt;code&gt;{@link Ext.data.Field#defaultValue defaultValue}&lt;/code&gt;.&lt;/div&gt;&lt;/li&gt;
  79. * &lt;li&gt;&lt;b&gt;rec&lt;/b&gt; : Mixed&lt;div class=&quot;sub-desc&quot;&gt;The data object containing the row as read by the Reader.
  80. * Depending on the Reader type, this could be an Array ({@link Ext.data.ArrayReader ArrayReader}), an object
  81. * ({@link Ext.data.JsonReader JsonReader}), or an XML element ({@link Ext.data.XMLReader XMLReader}).&lt;/div&gt;&lt;/li&gt;
  82. * &lt;/ul&gt;&lt;/div&gt;
  83. * &lt;pre&gt;&lt;code&gt;
  84. // example of convert function
  85. function fullName(v, record){
  86. return record.name.last + ', ' + record.name.first;
  87. }
  88. function location(v, record){
  89. return !record.city ? '' : (record.city + ', ' + record.state);
  90. }
  91. var Dude = Ext.data.Record.create([
  92. {name: 'fullname', convert: fullName},
  93. {name: 'firstname', mapping: 'name.first'},
  94. {name: 'lastname', mapping: 'name.last'},
  95. {name: 'city', defaultValue: 'homeless'},
  96. 'state',
  97. {name: 'location', convert: location}
  98. ]);
  99. // create the data store
  100. var store = new Ext.data.Store({
  101. reader: new Ext.data.JsonReader(
  102. {
  103. idProperty: 'key',
  104. root: 'daRoot',
  105. totalProperty: 'total'
  106. },
  107. Dude // recordType
  108. )
  109. });
  110. var myData = [
  111. { key: 1,
  112. name: { first: 'Fat', last: 'Albert' }
  113. // notice no city, state provided in data object
  114. },
  115. { key: 2,
  116. name: { first: 'Barney', last: 'Rubble' },
  117. city: 'Bedrock', state: 'Stoneridge'
  118. },
  119. { key: 3,
  120. name: { first: 'Cliff', last: 'Claven' },
  121. city: 'Boston', state: 'MA'
  122. }
  123. ];
  124. * &lt;/code&gt;&lt;/pre&gt;
  125. */
  126. <span id='Ext-data-Field-cfg-dateFormat'> /**
  127. </span> * @cfg {String} dateFormat
  128. * &lt;p&gt;(Optional) Used when converting received data into a Date when the {@link #type} is specified as &lt;code&gt;&quot;date&quot;&lt;/code&gt;.&lt;/p&gt;
  129. * &lt;p&gt;A format string for the {@link Date#parseDate Date.parseDate} function, or &quot;timestamp&quot; if the
  130. * value provided by the Reader is a UNIX timestamp, or &quot;time&quot; if the value provided by the Reader is a
  131. * javascript millisecond timestamp. See {@link Date}&lt;/p&gt;
  132. */
  133. dateFormat: null,
  134. <span id='Ext-data-Field-cfg-useNull'> /**
  135. </span> * @cfg {Boolean} useNull
  136. * &lt;p&gt;(Optional) Use when converting received data into a Number type (either int or float). If the value cannot be parsed,
  137. * null will be used if useNull is true, otherwise the value will be 0. Defaults to &lt;tt&gt;false&lt;/tt&gt;
  138. */
  139. useNull: false,
  140. <span id='Ext-data-Field-cfg-defaultValue'> /**
  141. </span> * @cfg {Mixed} defaultValue
  142. * (Optional) The default value used &lt;b&gt;when a Record is being created by a {@link Ext.data.Reader Reader}&lt;/b&gt;
  143. * when the item referenced by the &lt;code&gt;{@link Ext.data.Field#mapping mapping}&lt;/code&gt; does not exist in the data
  144. * object (i.e. undefined). (defaults to &quot;&quot;)
  145. */
  146. defaultValue: &quot;&quot;,
  147. <span id='Ext-data-Field-cfg-mapping'> /**
  148. </span> * @cfg {String/Number} mapping
  149. * &lt;p&gt;(Optional) A path expression for use by the {@link Ext.data.DataReader} implementation
  150. * that is creating the {@link Ext.data.Record Record} to extract the Field value from the data object.
  151. * If the path expression is the same as the field name, the mapping may be omitted.&lt;/p&gt;
  152. * &lt;p&gt;The form of the mapping expression depends on the Reader being used.&lt;/p&gt;
  153. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  154. * &lt;li&gt;{@link Ext.data.JsonReader}&lt;div class=&quot;sub-desc&quot;&gt;The mapping is a string containing the javascript
  155. * expression to reference the data from an element of the data item's {@link Ext.data.JsonReader#root root} Array. Defaults to the field name.&lt;/div&gt;&lt;/li&gt;
  156. * &lt;li&gt;{@link Ext.data.XmlReader}&lt;div class=&quot;sub-desc&quot;&gt;The mapping is an {@link Ext.DomQuery} path to the data
  157. * item relative to the DOM element that represents the {@link Ext.data.XmlReader#record record}. Defaults to the field name.&lt;/div&gt;&lt;/li&gt;
  158. * &lt;li&gt;{@link Ext.data.ArrayReader}&lt;div class=&quot;sub-desc&quot;&gt;The mapping is a number indicating the Array index
  159. * of the field's value. Defaults to the field specification's Array position.&lt;/div&gt;&lt;/li&gt;
  160. * &lt;/ul&gt;&lt;/div&gt;
  161. * &lt;p&gt;If a more complex value extraction strategy is required, then configure the Field with a {@link #convert}
  162. * function. This is passed the whole row object, and may interrogate it in whatever way is necessary in order to
  163. * return the desired data.&lt;/p&gt;
  164. */
  165. mapping: null,
  166. <span id='Ext-data-Field-cfg-sortType'> /**
  167. </span> * @cfg {Function} sortType
  168. * (Optional) A function which converts a Field's value to a comparable value in order to ensure
  169. * correct sort ordering. Predefined functions are provided in {@link Ext.data.SortTypes}. A custom
  170. * sort example:&lt;pre&gt;&lt;code&gt;
  171. // current sort after sort we want
  172. // +-+------+ +-+------+
  173. // |1|First | |1|First |
  174. // |2|Last | |3|Second|
  175. // |3|Second| |2|Last |
  176. // +-+------+ +-+------+
  177. sortType: function(value) {
  178. switch (value.toLowerCase()) // native toLowerCase():
  179. {
  180. case 'first': return 1;
  181. case 'second': return 2;
  182. default: return 3;
  183. }
  184. }
  185. * &lt;/code&gt;&lt;/pre&gt;
  186. */
  187. sortType : null,
  188. <span id='Ext-data-Field-cfg-sortDir'> /**
  189. </span> * @cfg {String} sortDir
  190. * (Optional) Initial direction to sort (&lt;code&gt;&quot;ASC&quot;&lt;/code&gt; or &lt;code&gt;&quot;DESC&quot;&lt;/code&gt;). Defaults to
  191. * &lt;code&gt;&quot;ASC&quot;&lt;/code&gt;.
  192. */
  193. sortDir : &quot;ASC&quot;,
  194. <span id='Ext-data-Field-cfg-allowBlank'> /**
  195. </span> * @cfg {Boolean} allowBlank
  196. * (Optional) Used for validating a {@link Ext.data.Record record}, defaults to &lt;code&gt;true&lt;/code&gt;.
  197. * An empty value here will cause {@link Ext.data.Record}.{@link Ext.data.Record#isValid isValid}
  198. * to evaluate to &lt;code&gt;false&lt;/code&gt;.
  199. */
  200. allowBlank : true
  201. });
  202. </pre>
  203. </body>
  204. </html>