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.

931 lines
24 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. setOptions(options)
  280. </td>
  281. <td>none</td>
  282. <td>
  283. Set options for the DataSet. Available options:
  284. <ul>
  285. <li>
  286. <code>queue</code><br>
  287. Queue data changes ('add', 'update', 'remove') and flush them at once.
  288. The queue can be flushed manually by calling
  289. <code>DataSet.flush()</code>, or can be flushed after a configured delay
  290. or maximum number of entries.
  291. <br>
  292. <br>
  293. When <code>queue</code> is true, a queue is created with default options.
  294. When <code>queue</code> is false, an existing queue will be flushed and removed.
  295. Options can be specified by providing an object:
  296. <ul>
  297. <li><code>delay: number</code><br>
  298. The queue will be flushed automatically after an inactivity of this
  299. delay in milliseconds. Default value is <code>null</code>.
  300. <li><code>max: number</code><br>
  301. When the queue exceeds the given maximum number
  302. of entries, the queue is flushed automatically.
  303. Default value is <code>Infinity</code>.
  304. </li>
  305. </ul>
  306. </li>
  307. </ul>
  308. </td>
  309. </tr>
  310. <tr>
  311. <td>
  312. update(data [, senderId])
  313. </td>
  314. <td>Number[]</td>
  315. <td>
  316. 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>.
  317. </td>
  318. </tr>
  319. </table>
  320. <h2 id="Subscriptions">Subscriptions</h2>
  321. <p>
  322. One can subscribe on changes in a DataSet.
  323. A subscription can be created using the method <code>on</code>,
  324. and removed with <code>off</code>.
  325. </p>
  326. <pre class="prettyprint lang-js">
  327. // create a DataSet
  328. var data = new vis.DataSet();
  329. // subscribe to any change in the DataSet
  330. data.on('*', function (event, properties, senderId) {
  331. console.log('event:', event, 'properties:', properties, 'senderId:', senderId);
  332. });
  333. // add an item
  334. data.add({id: 1, text: 'item 1'}); // triggers an 'add' event
  335. data.update({id: 1, text: 'item 1 (updated)'}); // triggers an 'update' event
  336. data.remove(1); // triggers an 'remove' event
  337. </pre>
  338. <h3 id="On">On</h3>
  339. <p>
  340. Subscribe to an event.
  341. </p>
  342. Syntax:
  343. <pre class="prettyprint lang-js">DataSet.on(event, callback)</pre>
  344. Where:
  345. <ul>
  346. <li>
  347. <code>event</code> is a String containing any of the events listed
  348. in section <a href="#Events">Events</a>.
  349. </li>
  350. <li>
  351. <code>callback</code> is a callback function which will be called
  352. each time the event occurs. The callback function is described in
  353. section <a href="#Callback">Callback</a>.
  354. </li>
  355. </ul>
  356. <h3 id="Off">Off</h3>
  357. <p>
  358. Unsubscribe from an event.
  359. </p>
  360. Syntax:
  361. <pre class="prettyprint lang-js">DataSet.off(event, callback)</pre>
  362. Where <code>event</code> and <code>callback</code> correspond with the
  363. parameters used to <a href="#On">subscribe</a> to the event.
  364. <h3 id="Events">Events</h3>
  365. <p>
  366. The following events are available for subscription:
  367. </p>
  368. <table>
  369. <tr>
  370. <th>Event</th>
  371. <th>Description</th>
  372. </tr>
  373. <tr>
  374. <td>add</td>
  375. <td>
  376. The <code>add</code> event is triggered when an item
  377. or a set of items is added, or when an item is updated while
  378. not yet existing.
  379. </td>
  380. </tr>
  381. <tr>
  382. <td>update</td>
  383. <td>
  384. The <code>update</code> event is triggered when an existing item
  385. or a set of existing items is updated.
  386. </td>
  387. </tr>
  388. <tr>
  389. <td>remove</td>
  390. <td>
  391. The <code>remove</code> event is triggered when an item
  392. or a set of items is removed.
  393. </td>
  394. </tr>
  395. <tr>
  396. <td>*</td>
  397. <td>
  398. The <code>*</code> event is triggered when any of the events
  399. <code>add</code>, <code>update</code>, and <code>remove</code>
  400. occurs.
  401. </td>
  402. </tr>
  403. </table>
  404. <h3 id="Callback">Callback</h3>
  405. <p>
  406. The callback functions of subscribers are called with the following
  407. parameters:
  408. </p>
  409. <pre class="prettyprint lang-js">
  410. function (event, properties, senderId) {
  411. // handle the event
  412. });
  413. </pre>
  414. <p>
  415. where the parameters are defined as
  416. </p>
  417. <table>
  418. <tr>
  419. <th>Parameter</th>
  420. <th>Type</th>
  421. <th>Description</th>
  422. </tr>
  423. <tr>
  424. <td>event</td>
  425. <td>String</td>
  426. <td>
  427. Any of the available events: <code>add</code>,
  428. <code>update</code>, or <code>remove</code>.
  429. </td>
  430. </tr>
  431. <tr>
  432. <td>properties</td>
  433. <td>Object&nbsp;|&nbsp;null</td>
  434. <td>
  435. Optional properties providing more information on the event.
  436. In case of the events <code>add</code>,
  437. <code>update</code>, and <code>remove</code>,
  438. <code>properties</code> is always an object containing a property
  439. <code>items</code>, which contains an array with the ids of the affected
  440. items. The <code>update</code> event has an extra field <code>data</code>
  441. containing the original data of the updated items, i.e. the gives the
  442. changed fields of the changed items.
  443. </td>
  444. </tr>
  445. <tr>
  446. <td>senderId</td>
  447. <td>String&nbsp;|&nbsp;Number</td>
  448. <td>
  449. An senderId, optionally provided by the application code
  450. which triggered the event. If senderId is not provided, the
  451. argument will be <code>null</code>.
  452. </td>
  453. </tr>
  454. </table>
  455. <h2 id="Data_Manipulation">Data Manipulation</h2>
  456. <p>
  457. The data in a DataSet can be manipulated using the methods
  458. <a href="#Add"><code>add</code></a>,
  459. <a href="#Update"><code>update</code></a>,
  460. and <a href="#Remove"><code>remove</code></a>.
  461. The DataSet can be emptied using the method
  462. <a href="#Clear"><code>clear</code></a>.
  463. </p>
  464. <pre class="prettyprint lang-js">
  465. // create a DataSet
  466. var data = new vis.DataSet();
  467. // add items
  468. data.add([
  469. {id: 1, text: 'item 1'},
  470. {id: 2, text: 'item 2'},
  471. {id: 3, text: 'item 3'}
  472. ]);
  473. // update an item
  474. data.update({id: 2, text: 'item 2 (updated)'});
  475. // remove an item
  476. data.remove(3);
  477. </pre>
  478. <h3 id="Add">Add</h3>
  479. <p>
  480. Add a data item or an array with items.
  481. </p>
  482. Syntax:
  483. <pre class="prettyprint lang-js">var addedIds = DataSet.add(data [, senderId])</pre>
  484. The argument <code>data</code> can contain:
  485. <ul>
  486. <li>
  487. An <code>Object</code> containing a single item to be
  488. added. The item must contain an id.
  489. </li>
  490. <li>
  491. An <code>Array</code> or
  492. <code>google.visualization.DataTable</code> containing
  493. a list with items to be added. Each item must contain
  494. an id.
  495. </li>
  496. </ul>
  497. <p>
  498. After the items are added to the DataSet, the DataSet will
  499. trigger an event <code>add</code>. When a <code>senderId</code>
  500. is provided, this id will be passed with the triggered
  501. event to all subscribers.
  502. </p>
  503. <p>
  504. The method will throw an Error when an item with the same id
  505. as any of the added items already exists.
  506. </p>
  507. <h3 id="Update">Update</h3>
  508. <p>
  509. Update a data item or an array with items.
  510. </p>
  511. Syntax:
  512. <pre class="prettyprint lang-js">var updatedIds = DataSet.update(data [, senderId])</pre>
  513. The argument <code>data</code> can contain:
  514. <ul>
  515. <li>
  516. An <code>Object</code> containing a single item to be
  517. updated. The item must contain an id.
  518. </li>
  519. <li>
  520. An <code>Array</code> or
  521. <code>google.visualization.DataTable</code> containing
  522. a list with items to be updated. Each item must contain
  523. an id.
  524. </li>
  525. </ul>
  526. <p>
  527. The provided properties will be merged in the existing item.
  528. When an item does not exist, it will be created.
  529. </p>
  530. <p>
  531. After the items are updated, the DataSet will
  532. trigger an event <code>add</code> for the added items, and
  533. an event <code>update</code>. When a <code>senderId</code>
  534. is provided, this id will be passed with the triggered
  535. event to all subscribers.
  536. </p>
  537. <h3 id="Remove">Remove</h3>
  538. <p>
  539. Remove a data item or an array with items.
  540. </p>
  541. Syntax:
  542. <pre class="prettyprint lang-js">var removedIds = DataSet.remove(id [, senderId])</pre>
  543. <p>
  544. The argument <code>id</code> can be:
  545. </p>
  546. <ul>
  547. <li>
  548. A <code>Number</code> or <code>String</code> containing the id
  549. of a single item to be removed.
  550. </li>
  551. <li>
  552. An <code>Object</code> containing the item to be deleted.
  553. The item will be deleted by its id.
  554. </li>
  555. <li>
  556. An Array containing ids or items to be removed.
  557. </li>
  558. </ul>
  559. <p>
  560. The method ignores removal of non-existing items, and returns an array
  561. containing the ids of the items which are actually removed from the
  562. DataSet.
  563. </p>
  564. <p>
  565. After the items are removed, the DataSet will
  566. trigger an event <code>remove</code> for the removed items.
  567. When a <code>senderId</code> is provided, this id will be passed with
  568. the triggered event to all subscribers.
  569. </p>
  570. <h3 id="Clear">Clear</h3>
  571. <p>
  572. Clear the complete DataSet.
  573. </p>
  574. Syntax:
  575. <pre class="prettyprint lang-js">var removedIds = DataSet.clear([senderId])</pre>
  576. <p>
  577. After the items are removed, the DataSet will
  578. trigger an event <code>remove</code> for all removed items.
  579. When a <code>senderId</code> is provided, this id will be passed with
  580. the triggered event to all subscribers.
  581. </p>
  582. <h2 id="Data_Selection">Data Selection</h2>
  583. <p>
  584. The DataSet contains functionality to format, filter, and sort data retrieved via the
  585. methods <code>get</code>, <code>getIds</code>, <code>forEach</code>, and <code>map</code>. These methods have the following syntax:
  586. </p>
  587. <pre class="prettyprint lang-js">
  588. DataSet.get([id] [, options] [, data]);
  589. DataSet.getIds([options]);
  590. DataSet.forEach(callback [, options]);
  591. DataSet.map(callback [, options]);
  592. </pre>
  593. <p>
  594. Where <code>options</code> is an Object which can have the following
  595. properties:
  596. </p>
  597. <table>
  598. <tr>
  599. <th>Name</th>
  600. <th>Type</th>
  601. <th>Description</th>
  602. </tr>
  603. <tr>
  604. <td>fields</td>
  605. <td>String[&nbsp;]</td>
  606. <td>
  607. An array with field names.
  608. By default, all properties of the items are emitted.
  609. When <code>fields</code> is defined, only the properties
  610. whose name is specified in <code>fields</code> will be included
  611. in the returned items.
  612. </td>
  613. </tr>
  614. <tr>
  615. <td>type</td>
  616. <td>Object.&lt;String,&nbsp;String&gt;</td>
  617. <td>
  618. An object containing field names as key, and data types as value.
  619. By default, the type of the properties of an item are left
  620. unchanged. When a field type is specified, this field in the
  621. items will be converted to the specified type. This can be used
  622. for example to convert ISO strings containing a date to a
  623. JavaScript Date object, or convert strings to numbers or vice
  624. versa. The available data types are listed in section
  625. <a href="#Data_Types">Data Types</a>.
  626. </td>
  627. </tr>
  628. <tr>
  629. <td>filter</td>
  630. <td>Function</td>
  631. <td>Items can be filtered on specific properties by providing a filter
  632. function. A filter function is executed for each of the items in the
  633. DataSet, and is called with the item as parameter. The function must
  634. return a boolean. All items for which the filter function returns
  635. true will be emitted.
  636. See section <a href="#Data_Filtering">Data Filtering</a>.</td>
  637. </tr>
  638. <tr>
  639. <td>order</td>
  640. <td>String | Function</td>
  641. <td>Order the items by a field name or custom sort function.</td>
  642. </tr>
  643. <tr>
  644. <td>returnType</td>
  645. <td>String</td>
  646. <td>Determine the type of output of the get function. Allowed values are <code>Array | Object | DataTable</code>.
  647. 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>
  648. </tr>
  649. </table>
  650. <p>
  651. The following example demonstrates formatting properties and filtering
  652. properties from items.
  653. </p>
  654. <pre class="prettyprint lang-js">
  655. // create a DataSet
  656. var data = new vis.DataSet();
  657. data.add([
  658. {id: 1, text: 'item 1', date: '2013-06-20', group: 1, first: true},
  659. {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
  660. {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
  661. {id: 4, text: 'item 4'}
  662. ]);
  663. // retrieve formatted items
  664. var items = data.get({
  665. fields: ['id', 'date', 'group'], // output the specified fields only
  666. type: {
  667. date: 'Date', // convert the date fields to Date objects
  668. group: 'String' // convert the group fields to Strings
  669. }
  670. });
  671. </pre>
  672. <h3 id="Getting_Data">Getting Data</h3>
  673. <p>
  674. Data can be retrieved from the DataSet using the method <code>get</code>.
  675. This method can return a single item or a list with items.
  676. </p>
  677. <p>A single item can be retrieved by its id:</p>
  678. <pre class="prettyprint lang-js">
  679. var item1 = dataset.get(1);
  680. </pre>
  681. <p>A selection of items can be retrieved by providing an array with ids:</p>
  682. <pre class="prettyprint lang-js">
  683. var items = dataset.get([1, 3, 4]); // retrieve items 1, 3, and 4
  684. </pre>
  685. <p>All items can be retrieved by simply calling <code>get</code> without
  686. specifying an id:</p>
  687. <pre class="prettyprint lang-js">
  688. var items = dataset.get(); // retrieve all items
  689. </pre>
  690. <h3 id="Data_Filtering">Data Filtering</h3>
  691. <p>
  692. Items can be filtered on specific properties by providing a filter
  693. function. A filter function is executed for each of the items in the
  694. DataSet, and is called with the item as parameter. The function must
  695. return a boolean. All items for which the filter function returns
  696. true will be emitted.
  697. </p>
  698. <pre class="prettyprint lang-js">
  699. // retrieve all items having a property group with value 2
  700. var group2 = dataset.get({
  701. filter: function (item) {
  702. return (item.group == 2);
  703. }
  704. });
  705. // retrieve all items having a property balance with a value above zero
  706. var positiveBalance = dataset.get({
  707. filter: function (item) {
  708. return (item.balance > 0);
  709. }
  710. });
  711. </pre>
  712. <h3 id="Data_Types">Data Types</h3>
  713. <p>
  714. DataSet supports the following data types:
  715. </p>
  716. <table style="width: 100%">
  717. <tr>
  718. <th>Name</th>
  719. <th>Description</th>
  720. <th>Examples</th>
  721. </tr>
  722. <tr>
  723. <td>Boolean</td>
  724. <td>A JavaScript Boolean</td>
  725. <td>
  726. <code>true</code><br>
  727. <code>false</code>
  728. </td>
  729. </tr>
  730. <tr>
  731. <td>Number</td>
  732. <td>A JavaScript Number</td>
  733. <td>
  734. <code>32</code><br>
  735. <code>2.4</code>
  736. </td>
  737. </tr>
  738. <tr>
  739. <td>String</td>
  740. <td>A JavaScript String</td>
  741. <td>
  742. <code>"hello world"</code><br>
  743. <code>"2013-06-28"</code>
  744. </td>
  745. </tr>
  746. <tr>
  747. <td>Date</td>
  748. <td>A JavaScript Date object</td>
  749. <td>
  750. <code>new Date()</code><br>
  751. <code>new Date(2013, 5, 28)</code><br>
  752. <code>new Date(1372370400000)</code>
  753. </td>
  754. </tr>
  755. <tr>
  756. <td>Moment</td>
  757. <td>A Moment object, created with
  758. <a href="http://momentjs.com/" target="_blank">moment.js</a></td>
  759. <td>
  760. <code>moment()</code><br>
  761. <code>moment('2013-06-28')</code>
  762. </td>
  763. </tr>
  764. <tr>
  765. <td>ISODate</td>
  766. <td>A string containing an ISO Date</td>
  767. <td>
  768. <code>new Date().toISOString()</code><br>
  769. <code>"2013-06-27T22:00:00.000Z"</code>
  770. </td>
  771. </tr>
  772. <tr>
  773. <td>ASPDate</td>
  774. <td>A string containing an ASP Date</td>
  775. <td>
  776. <code>"/Date(1372370400000)/"</code><br>
  777. <code>"/Date(1198908717056-0700)/"</code>
  778. </td>
  779. </tr>
  780. </table>
  781. <h2 id="Data_Policy">Data Policy</h2>
  782. <p>
  783. All code and data is processed and rendered in the browser.
  784. No data is sent to any server.
  785. </p>
  786. </div>
  787. </body>
  788. </html>