vis.js is a dynamic, browser-based visualization library
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.

897 lines
23 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>vis.js | DataSet documentation</title>
  5. <link href="css/prettify.css" type="text/css" rel="stylesheet" />
  6. <link href='css/style.css' type='text/css' rel='stylesheet'>
  7. <script type="text/javascript" src="lib/prettify/prettify.js"></script>
  8. </head>
  9. <body onload="prettyPrint();">
  10. <div id="container">
  11. <h1>DataSet documentation</h1>
  12. <h2 id="Contents">Contents</h2>
  13. <ul>
  14. <li><a href="#Overview">Overview</a></li>
  15. <li><a href="#Example">Example</a></li>
  16. <li><a href="#Construction">Construction</a></li>
  17. <li><a href="#Methods">Methods</a></li>
  18. <li><a href="#Subscriptions">Subscriptions</a></li>
  19. <li><a href="#Data_Manipulation">Data Manipulation</a></li>
  20. <li><a href="#Data_Selection">Data Selection</a></li>
  21. <li><a href="#Data_Policy">Data Policy</a></li>
  22. </ul>
  23. <h2 id="Overview">Overview</h2>
  24. <p>
  25. Vis.js comes with a flexible DataSet, which can be used to hold and
  26. manipulate unstructured data and listen for changes in the data.
  27. The DataSet is key/value based. Data items can be added, updated and
  28. removed from the DatSet, and one can subscribe to changes in the DataSet.
  29. The data in the DataSet can be filtered and ordered, and fields (like
  30. dates) can be converted to a specific type. Data can be normalized when
  31. appending it to the DataSet as well.
  32. </p>
  33. <h2 id="Example">Example</h2>
  34. <p>
  35. The following example shows how to use a DataSet.
  36. </p>
  37. <pre class="prettyprint lang-js">
  38. // create a DataSet
  39. var options = {};
  40. var data = new vis.DataSet(options);
  41. // add items
  42. // note that the data items can contain different properties and data formats
  43. data.add([
  44. {id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
  45. {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
  46. {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
  47. {id: 4, text: 'item 4'}
  48. ]);
  49. // subscribe to any change in the DataSet
  50. data.on('*', function (event, properties, senderId) {
  51. console.log('event', event, properties);
  52. });
  53. // update an existing item
  54. data.update({id: 2, group: 1});
  55. // remove an item
  56. data.remove(4);
  57. // get all ids
  58. var ids = data.getIds();
  59. console.log('ids', ids);
  60. // get a specific item
  61. var item1 = data.get(1);
  62. console.log('item1', item1);
  63. // retrieve a filtered subset of the data
  64. var items = data.get({
  65. filter: function (item) {
  66. return item.group == 1;
  67. }
  68. });
  69. console.log('filtered items', items);
  70. // retrieve formatted items
  71. var items = data.get({
  72. fields: ['id', 'date'],
  73. type: {
  74. date: 'ISODate'
  75. }
  76. });
  77. console.log('formatted items', items);
  78. </pre>
  79. <h2 id="Construction">Construction</h2>
  80. <p>
  81. A DataSet can be constructed as:
  82. </p>
  83. <pre class="prettyprint lang-js">
  84. var data = new vis.DataSet([data] [, options])
  85. </pre>
  86. <p>
  87. After construction, data can be added to the DataSet using the methods
  88. <code>add</code> and <code>update</code>, as described in section
  89. <a href="#Data_Manipulation">Data Manipulation</a>.
  90. </p>
  91. <p>
  92. The parameter <code>data</code> is optional and can be an Array or
  93. <a href="https://developers.google.com/chart/interactive/docs/reference#DataTable" target="_blank">Google DataTable</a> with items.
  94. </p>
  95. <p>
  96. The parameter <code>options</code> is optional and is an object which can
  97. contain the following properties:
  98. </p>
  99. <table>
  100. <tr>
  101. <th>Name</th>
  102. <th>Type</th>
  103. <th>Default value</th>
  104. <th>Description</th>
  105. </tr>
  106. <tr>
  107. <td>fieldId</td>
  108. <td>String</td>
  109. <td>"id"</td>
  110. <td>
  111. The name of the field containing the id of the items.
  112. When data is fetched from a server which uses some specific
  113. field to identify items, this field name can be specified
  114. in the DataSet using the option <code>fieldId</code>.
  115. For example <a href="http://couchdb.apache.org/"
  116. target="_blank">CouchDB</a> uses the field
  117. <code>"_id"</code> to identify documents.
  118. </td>
  119. </tr>
  120. <tr>
  121. <td>type</td>
  122. <td>Object.&lt;String,&nbsp;String&gt;</td>
  123. <td>none</td>
  124. <td>
  125. An object containing field names as key, and data types as
  126. value. By default, the type of the properties of items are left
  127. unchanged. Item properties can be normalized by specifying a
  128. field type. This is useful for example to automatically convert
  129. stringified dates coming from a server into JavaScript Date
  130. objects. The available data types are listed in section
  131. <a href="#Data_Types">Data Types</a>.
  132. </td>
  133. </tr>
  134. <tr>
  135. <td>queue</td>
  136. <td>Object | boolean</td>
  137. <td>none</td>
  138. <td>
  139. Queue data changes ('add', 'update', 'remove') and flush them at once.
  140. The queue can be flushed manually by calling
  141. <code>DataSet.flush()</code>, or can be flushed after a configured delay
  142. or maximum number of entries.
  143. <br>
  144. <br>
  145. When <code>queue</code> is true, a queue is created
  146. with default options. Options can be specified by providing an object:
  147. <ul>
  148. <li><code>delay: number</code><br>
  149. The queue will be flushed automatically after an inactivity of this
  150. delay in milliseconds. Default value is <code>null</code>.
  151. <li><code>max: number</code><br>
  152. When the queue exceeds the given maximum number
  153. of entries, the queue is flushed automatically.
  154. Default value is <code>Infinity</code>.
  155. </li>
  156. </ul>
  157. </td>
  158. </tr>
  159. </table>
  160. <h2 id="Methods">Methods</h2>
  161. <p>DataSet contains the following methods.</p>
  162. <table>
  163. <colgroup>
  164. <col width="200">
  165. </colgroup>
  166. <tr>
  167. <th>Method</th>
  168. <th>Return Type</th>
  169. <th>Description</th>
  170. </tr>
  171. <tr>
  172. <td>add(data [, senderId])</td>
  173. <td>Number[]</td>
  174. <td>Add one or multiple items to the DataSet. <code>data</code> can be a single item or an array with items. Adding an item will fail when there already is an item with the same id. The function returns an array with the ids of the added items. See section <a href="#Data_Manipulation">Data Manipulation</a>.</td>
  175. </tr>
  176. <tr>
  177. <td>clear([senderId])</td>
  178. <td>Number[]</td>
  179. <td>Clear all data from the DataSet. The function returns an array with the ids of the removed items.</td>
  180. </tr>
  181. <tr>
  182. <td>distinct(field)</td>
  183. <td>Array</td>
  184. <td>Find all distinct values of a specified field. Returns an unordered array containing all distinct values. If data items do not contain the specified field are ignored.</td>
  185. </tr>
  186. <tr>
  187. <td>flush()</td>
  188. <td>none</td>
  189. <td>Flush queued changes. Only available when the DataSet is configured with the option <code>queue</code>, see section <a href="#Construction">Construction</a>.</td>
  190. </tr>
  191. <tr>
  192. <td>forEach(callback [, options])</td>
  193. <td>none</td>
  194. <td>
  195. Execute a callback function for every item in the dataset.
  196. The available options are described in section <a href="#Data_Selection">Data Selection</a>.
  197. </td>
  198. </tr>
  199. <tr>
  200. <td>
  201. get([options] [, data])<br>
  202. get(id [,options] [, data])<br>
  203. get(ids [, options] [, data])
  204. </td>
  205. <td>Object | Array | DataTable</td>
  206. <td>
  207. Get a single item, multiple items, or all items from the DataSet.
  208. Usage examples can be found in section <a href="#Getting_Data">Getting Data</a>, and the available <code>options</code> are described in section <a href="#Data_Selection">Data Selection</a>. If parameter <code>data</code> is provided, items will be appended to this array or table, which is required in case of Google DataTable.
  209. </td>
  210. </tr>
  211. <tr>
  212. <td>
  213. getDataSet()
  214. </td>
  215. <td>DataSet</td>
  216. <td>
  217. Get the DataSet itself. In case of a DataView, this function does not
  218. return the DataSet to which the DataView is connected.
  219. </td>
  220. </tr>
  221. <tr>
  222. <td>
  223. getIds([options])
  224. </td>
  225. <td>Number[]</td>
  226. <td>
  227. Get ids of all items or of a filtered set of items.
  228. Available <code>options</code> are described in section <a href="#Data_Selection">Data Selection</a>, except that options <code>fields</code> and <code>type</code> are not applicable in case of <code>getIds</code>.
  229. </td>
  230. </tr>
  231. <tr>
  232. <td>map(callback [, options])</td>
  233. <td>Array</td>
  234. <td>
  235. Map every item in the DataSet.
  236. The available options are described in section <a href="#Data_Selection">Data Selection</a>.
  237. </td>
  238. </tr>
  239. <tr>
  240. <td>max(field)</td>
  241. <td>Object | null</td>
  242. <td>
  243. Find the item with maximum value of specified field. Returns <code>null</code> if no item is found.
  244. </td>
  245. </tr>
  246. <tr>
  247. <td>min(field)</td>
  248. <td>Object | null</td>
  249. <td>
  250. Find the item with minimum value of specified field. Returns <code>null</code> if no item is found.
  251. </td>
  252. </tr>
  253. <tr>
  254. <td>off(event, callback)</td>
  255. <td>none</td>
  256. <td>
  257. Unsubscribe from an event, remove an event listener. See section <a href="#Subscriptions">Subscriptions</a>.
  258. </td>
  259. </tr>
  260. <tr>
  261. <td>on(event, callback)</td>
  262. <td>none</td>
  263. <td>
  264. Subscribe to an event, add an event listener. See section <a href="#Subscriptions">Subscriptions</a>.
  265. </td>
  266. </tr>
  267. <tr>
  268. <td>
  269. remove(id [, senderId])<br>
  270. remove(ids [, senderId])
  271. </td>
  272. <td>Number[]</td>
  273. <td>
  274. Remove one or multiple items by id or by the items themselves. Returns an array with the ids of the removed items. See section <a href="#Data_Manipulation">Data Manipulation</a>.
  275. </td>
  276. </tr>
  277. <tr>
  278. <td>
  279. update(data [, senderId])
  280. </td>
  281. <td>Number[]</td>
  282. <td>
  283. Update on ore multiple existing items. <code>data</code> can be a single item or an array with items. When an item doesn't exist, it will be created. Returns an array with the ids of the removed items. See section <a href="#Data_Manipulation">Data Manipulation</a>.
  284. </td>
  285. </tr>
  286. </table>
  287. <h2 id="Subscriptions">Subscriptions</h2>
  288. <p>
  289. One can subscribe on changes in a DataSet.
  290. A subscription can be created using the method <code>on</code>,
  291. and removed with <code>off</code>.
  292. </p>
  293. <pre class="prettyprint lang-js">
  294. // create a DataSet
  295. var data = new vis.DataSet();
  296. // subscribe to any change in the DataSet
  297. data.on('*', function (event, properties, senderId) {
  298. console.log('event:', event, 'properties:', properties, 'senderId:', senderId);
  299. });
  300. // add an item
  301. data.add({id: 1, text: 'item 1'}); // triggers an 'add' event
  302. data.update({id: 1, text: 'item 1 (updated)'}); // triggers an 'update' event
  303. data.remove(1); // triggers an 'remove' event
  304. </pre>
  305. <h3 id="On">On</h3>
  306. <p>
  307. Subscribe to an event.
  308. </p>
  309. Syntax:
  310. <pre class="prettyprint lang-js">DataSet.on(event, callback)</pre>
  311. Where:
  312. <ul>
  313. <li>
  314. <code>event</code> is a String containing any of the events listed
  315. in section <a href="#Events">Events</a>.
  316. </li>
  317. <li>
  318. <code>callback</code> is a callback function which will be called
  319. each time the event occurs. The callback function is described in
  320. section <a href="#Callback">Callback</a>.
  321. </li>
  322. </ul>
  323. <h3 id="Off">Off</h3>
  324. <p>
  325. Unsubscribe from an event.
  326. </p>
  327. Syntax:
  328. <pre class="prettyprint lang-js">DataSet.off(event, callback)</pre>
  329. Where <code>event</code> and <code>callback</code> correspond with the
  330. parameters used to <a href="#On">subscribe</a> to the event.
  331. <h3 id="Events">Events</h3>
  332. <p>
  333. The following events are available for subscription:
  334. </p>
  335. <table>
  336. <tr>
  337. <th>Event</th>
  338. <th>Description</th>
  339. </tr>
  340. <tr>
  341. <td>add</td>
  342. <td>
  343. The <code>add</code> event is triggered when an item
  344. or a set of items is added, or when an item is updated while
  345. not yet existing.
  346. </td>
  347. </tr>
  348. <tr>
  349. <td>update</td>
  350. <td>
  351. The <code>update</code> event is triggered when an existing item
  352. or a set of existing items is updated.
  353. </td>
  354. </tr>
  355. <tr>
  356. <td>remove</td>
  357. <td>
  358. The <code>remove</code> event is triggered when an item
  359. or a set of items is removed.
  360. </td>
  361. </tr>
  362. <tr>
  363. <td>*</td>
  364. <td>
  365. The <code>*</code> event is triggered when any of the events
  366. <code>add</code>, <code>update</code>, and <code>remove</code>
  367. occurs.
  368. </td>
  369. </tr>
  370. </table>
  371. <h3 id="Callback">Callback</h3>
  372. <p>
  373. The callback functions of subscribers are called with the following
  374. parameters:
  375. </p>
  376. <pre class="prettyprint lang-js">
  377. function (event, properties, senderId) {
  378. // handle the event
  379. });
  380. </pre>
  381. <p>
  382. where the parameters are defined as
  383. </p>
  384. <table>
  385. <tr>
  386. <th>Parameter</th>
  387. <th>Type</th>
  388. <th>Description</th>
  389. </tr>
  390. <tr>
  391. <td>event</td>
  392. <td>String</td>
  393. <td>
  394. Any of the available events: <code>add</code>,
  395. <code>update</code>, or <code>remove</code>.
  396. </td>
  397. </tr>
  398. <tr>
  399. <td>properties</td>
  400. <td>Object&nbsp;|&nbsp;null</td>
  401. <td>
  402. Optional properties providing more information on the event.
  403. In case of the events <code>add</code>,
  404. <code>update</code>, and <code>remove</code>,
  405. <code>properties</code> is always an object containing a property
  406. <code>items</code>, which contains an array with the ids of the affected
  407. items. The <code>update</code> event has an extra field <code>data</code>
  408. containing the original data of the updated items, i.e. the gives the
  409. changed fields of the changed items.
  410. </td>
  411. </tr>
  412. <tr>
  413. <td>senderId</td>
  414. <td>String&nbsp;|&nbsp;Number</td>
  415. <td>
  416. An senderId, optionally provided by the application code
  417. which triggered the event. If senderId is not provided, the
  418. argument will be <code>null</code>.
  419. </td>
  420. </tr>
  421. </table>
  422. <h2 id="Data_Manipulation">Data Manipulation</h2>
  423. <p>
  424. The data in a DataSet can be manipulated using the methods
  425. <a href="#Add"><code>add</code></a>,
  426. <a href="#Update"><code>update</code></a>,
  427. and <a href="#Remove"><code>remove</code></a>.
  428. The DataSet can be emptied using the method
  429. <a href="#Clear"><code>clear</code></a>.
  430. </p>
  431. <pre class="prettyprint lang-js">
  432. // create a DataSet
  433. var data = new vis.DataSet();
  434. // add items
  435. data.add([
  436. {id: 1, text: 'item 1'},
  437. {id: 2, text: 'item 2'},
  438. {id: 3, text: 'item 3'}
  439. ]);
  440. // update an item
  441. data.update({id: 2, text: 'item 2 (updated)'});
  442. // remove an item
  443. data.remove(3);
  444. </pre>
  445. <h3 id="Add">Add</h3>
  446. <p>
  447. Add a data item or an array with items.
  448. </p>
  449. Syntax:
  450. <pre class="prettyprint lang-js">var addedIds = DataSet.add(data [, senderId])</pre>
  451. The argument <code>data</code> can contain:
  452. <ul>
  453. <li>
  454. An <code>Object</code> containing a single item to be
  455. added. The item must contain an id.
  456. </li>
  457. <li>
  458. An <code>Array</code> or
  459. <code>google.visualization.DataTable</code> containing
  460. a list with items to be added. Each item must contain
  461. an id.
  462. </li>
  463. </ul>
  464. <p>
  465. After the items are added to the DataSet, the DataSet will
  466. trigger an event <code>add</code>. When a <code>senderId</code>
  467. is provided, this id will be passed with the triggered
  468. event to all subscribers.
  469. </p>
  470. <p>
  471. The method will throw an Error when an item with the same id
  472. as any of the added items already exists.
  473. </p>
  474. <h3 id="Update">Update</h3>
  475. <p>
  476. Update a data item or an array with items.
  477. </p>
  478. Syntax:
  479. <pre class="prettyprint lang-js">var updatedIds = DataSet.update(data [, senderId])</pre>
  480. The argument <code>data</code> can contain:
  481. <ul>
  482. <li>
  483. An <code>Object</code> containing a single item to be
  484. updated. The item must contain an id.
  485. </li>
  486. <li>
  487. An <code>Array</code> or
  488. <code>google.visualization.DataTable</code> containing
  489. a list with items to be updated. Each item must contain
  490. an id.
  491. </li>
  492. </ul>
  493. <p>
  494. The provided properties will be merged in the existing item.
  495. When an item does not exist, it will be created.
  496. </p>
  497. <p>
  498. After the items are updated, the DataSet will
  499. trigger an event <code>add</code> for the added items, and
  500. an event <code>update</code>. When a <code>senderId</code>
  501. is provided, this id will be passed with the triggered
  502. event to all subscribers.
  503. </p>
  504. <h3 id="Remove">Remove</h3>
  505. <p>
  506. Remove a data item or an array with items.
  507. </p>
  508. Syntax:
  509. <pre class="prettyprint lang-js">var removedIds = DataSet.remove(id [, senderId])</pre>
  510. <p>
  511. The argument <code>id</code> can be:
  512. </p>
  513. <ul>
  514. <li>
  515. A <code>Number</code> or <code>String</code> containing the id
  516. of a single item to be removed.
  517. </li>
  518. <li>
  519. An <code>Object</code> containing the item to be deleted.
  520. The item will be deleted by its id.
  521. </li>
  522. <li>
  523. An Array containing ids or items to be removed.
  524. </li>
  525. </ul>
  526. <p>
  527. The method ignores removal of non-existing items, and returns an array
  528. containing the ids of the items which are actually removed from the
  529. DataSet.
  530. </p>
  531. <p>
  532. After the items are removed, the DataSet will
  533. trigger an event <code>remove</code> for the removed items.
  534. When a <code>senderId</code> is provided, this id will be passed with
  535. the triggered event to all subscribers.
  536. </p>
  537. <h3 id="Clear">Clear</h3>
  538. <p>
  539. Clear the complete DataSet.
  540. </p>
  541. Syntax:
  542. <pre class="prettyprint lang-js">var removedIds = DataSet.clear([senderId])</pre>
  543. <p>
  544. After the items are removed, the DataSet will
  545. trigger an event <code>remove</code> for all removed items.
  546. When a <code>senderId</code> is provided, this id will be passed with
  547. the triggered event to all subscribers.
  548. </p>
  549. <h2 id="Data_Selection">Data Selection</h2>
  550. <p>
  551. The DataSet contains functionality to format, filter, and sort data retrieved via the
  552. methods <code>get</code>, <code>getIds</code>, <code>forEach</code>, and <code>map</code>. These methods have the following syntax:
  553. </p>
  554. <pre class="prettyprint lang-js">
  555. DataSet.get([id] [, options] [, data]);
  556. DataSet.getIds([options]);
  557. DataSet.forEach(callback [, options]);
  558. DataSet.map(callback [, options]);
  559. </pre>
  560. <p>
  561. Where <code>options</code> is an Object which can have the following
  562. properties:
  563. </p>
  564. <table>
  565. <tr>
  566. <th>Name</th>
  567. <th>Type</th>
  568. <th>Description</th>
  569. </tr>
  570. <tr>
  571. <td>fields</td>
  572. <td>String[&nbsp;]</td>
  573. <td>
  574. An array with field names.
  575. By default, all properties of the items are emitted.
  576. When <code>fields</code> is defined, only the properties
  577. whose name is specified in <code>fields</code> will be included
  578. in the returned items.
  579. </td>
  580. </tr>
  581. <tr>
  582. <td>type</td>
  583. <td>Object.&lt;String,&nbsp;String&gt;</td>
  584. <td>
  585. An object containing field names as key, and data types as value.
  586. By default, the type of the properties of an item are left
  587. unchanged. When a field type is specified, this field in the
  588. items will be converted to the specified type. This can be used
  589. for example to convert ISO strings containing a date to a
  590. JavaScript Date object, or convert strings to numbers or vice
  591. versa. The available data types are listed in section
  592. <a href="#Data_Types">Data Types</a>.
  593. </td>
  594. </tr>
  595. <tr>
  596. <td>filter</td>
  597. <td>Function</td>
  598. <td>Items can be filtered on specific properties by providing a filter
  599. function. A filter function is executed for each of the items in the
  600. DataSet, and is called with the item as parameter. The function must
  601. return a boolean. All items for which the filter function returns
  602. true will be emitted.
  603. See section <a href="#Data_Filtering">Data Filtering</a>.</td>
  604. </tr>
  605. <tr>
  606. <td>order</td>
  607. <td>String | Function</td>
  608. <td>Order the items by a field name or custom sort function.</td>
  609. </tr>
  610. <tr>
  611. <td>returnType</td>
  612. <td>String</td>
  613. <td>Determine the type of output of the get function. Allowed values are <code>Array | Object | DataTable</code>.
  614. The <code>DataTable</code> refers to a Google DataTable. The default returnType is an array. The object type will return a JSON object with the ID's as keys.</td>
  615. </tr>
  616. </table>
  617. <p>
  618. The following example demonstrates formatting properties and filtering
  619. properties from items.
  620. </p>
  621. <pre class="prettyprint lang-js">
  622. // create a DataSet
  623. var data = new vis.DataSet();
  624. data.add([
  625. {id: 1, text: 'item 1', date: '2013-06-20', group: 1, first: true},
  626. {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
  627. {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
  628. {id: 4, text: 'item 4'}
  629. ]);
  630. // retrieve formatted items
  631. var items = data.get({
  632. fields: ['id', 'date', 'group'], // output the specified fields only
  633. type: {
  634. date: 'Date', // convert the date fields to Date objects
  635. group: 'String' // convert the group fields to Strings
  636. }
  637. });
  638. </pre>
  639. <h3 id="Getting_Data">Getting Data</h3>
  640. <p>
  641. Data can be retrieved from the DataSet using the method <code>get</code>.
  642. This method can return a single item or a list with items.
  643. </p>
  644. <p>A single item can be retrieved by its id:</p>
  645. <pre class="prettyprint lang-js">
  646. var item1 = dataset.get(1);
  647. </pre>
  648. <p>A selection of items can be retrieved by providing an array with ids:</p>
  649. <pre class="prettyprint lang-js">
  650. var items = dataset.get([1, 3, 4]); // retrieve items 1, 3, and 4
  651. </pre>
  652. <p>All items can be retrieved by simply calling <code>get</code> without
  653. specifying an id:</p>
  654. <pre class="prettyprint lang-js">
  655. var items = dataset.get(); // retrieve all items
  656. </pre>
  657. <h3 id="Data_Filtering">Data Filtering</h3>
  658. <p>
  659. Items can be filtered on specific properties by providing a filter
  660. function. A filter function is executed for each of the items in the
  661. DataSet, and is called with the item as parameter. The function must
  662. return a boolean. All items for which the filter function returns
  663. true will be emitted.
  664. </p>
  665. <pre class="prettyprint lang-js">
  666. // retrieve all items having a property group with value 2
  667. var group2 = dataset.get({
  668. filter: function (item) {
  669. return (item.group == 2);
  670. }
  671. });
  672. // retrieve all items having a property balance with a value above zero
  673. var positiveBalance = dataset.get({
  674. filter: function (item) {
  675. return (item.balance > 0);
  676. }
  677. });
  678. </pre>
  679. <h3 id="Data_Types">Data Types</h3>
  680. <p>
  681. DataSet supports the following data types:
  682. </p>
  683. <table style="width: 100%">
  684. <tr>
  685. <th>Name</th>
  686. <th>Description</th>
  687. <th>Examples</th>
  688. </tr>
  689. <tr>
  690. <td>Boolean</td>
  691. <td>A JavaScript Boolean</td>
  692. <td>
  693. <code>true</code><br>
  694. <code>false</code>
  695. </td>
  696. </tr>
  697. <tr>
  698. <td>Number</td>
  699. <td>A JavaScript Number</td>
  700. <td>
  701. <code>32</code><br>
  702. <code>2.4</code>
  703. </td>
  704. </tr>
  705. <tr>
  706. <td>String</td>
  707. <td>A JavaScript String</td>
  708. <td>
  709. <code>"hello world"</code><br>
  710. <code>"2013-06-28"</code>
  711. </td>
  712. </tr>
  713. <tr>
  714. <td>Date</td>
  715. <td>A JavaScript Date object</td>
  716. <td>
  717. <code>new Date()</code><br>
  718. <code>new Date(2013, 5, 28)</code><br>
  719. <code>new Date(1372370400000)</code>
  720. </td>
  721. </tr>
  722. <tr>
  723. <td>Moment</td>
  724. <td>A Moment object, created with
  725. <a href="http://momentjs.com/" target="_blank">moment.js</a></td>
  726. <td>
  727. <code>moment()</code><br>
  728. <code>moment('2013-06-28')</code>
  729. </td>
  730. </tr>
  731. <tr>
  732. <td>ISODate</td>
  733. <td>A string containing an ISO Date</td>
  734. <td>
  735. <code>new Date().toISOString()</code><br>
  736. <code>"2013-06-27T22:00:00.000Z"</code>
  737. </td>
  738. </tr>
  739. <tr>
  740. <td>ASPDate</td>
  741. <td>A string containing an ASP Date</td>
  742. <td>
  743. <code>"/Date(1372370400000)/"</code><br>
  744. <code>"/Date(1198908717056-0700)/"</code>
  745. </td>
  746. </tr>
  747. </table>
  748. <h2 id="Data_Policy">Data Policy</h2>
  749. <p>
  750. All code and data is processed and rendered in the browser.
  751. No data is sent to any server.
  752. </p>
  753. </div>
  754. </body>
  755. </html>