gridx.core.model.Model
Object » gridx.core.model.Model
dojo.require("gridx.core.model.Model");
Defined in gridx/core/model/Model.js
It provides a clean and useful set of APIs to encapsulate complicated data operations, even for huge asynchronous (server side) data stores. It is built upon a simple extension mechanism, allowing new (even user defined) data operaions to be pluged in. An instance of this class can be regarded as a stand-alone logic grid providing consistent data processing functionalities. This class can even be instanticated alone without any grid UI.
Method Summary
- _addCmd(args)
- _cmdRequest()
- _createExts(exts, args)
- _exec()
- _execEvents(scope, callback)
- _msg()
- _normArgs(args)
- _onSizeChange()
- byId(id) returns gridx.core.model.__RowCache Get the row cache by row id
- byIndex(index, parentId) returns gridx.core.model.__RowCache Get the row cache by row index.
- children(id) returns Array Get IDs of children rows.
- clearCache()
- constructor(args)
- destroy()
- free(id) Unlock a row cache in memory, so that it could be cleared out when cache size is reached.
- hasChildren(id) returns Boolean Check whether a row has children rows.
- idToIndex(id) returns Integer Transform row ID to row index
- indexToId(index, parentId) returns String Transform row index to row ID
- isId(id)
- keep(id) Lock up a row cache in memory, avoid clearing it out when cache size is reached.
- parent(id) Get the parent ID of the given row.
- scan(args, callback) returns dojo.Deferred Go through all the rows in several batches from start to end (or according to given args), and execute the callback function for every batch of rows.
- setStore(store)
- size(parentId) returns Integer Get the count of rows under the given parent.
- treePath(id) returns String[] Get tree path of row by row ID
- when(args, callback, scope) returns dojo.Deferred Call this method to make sure all the pending data operations are executed and all the needed rows are at client side.
Event Summary
- onDelete() Fired when a row is deleted from store
- onNew() Fired when a row is added to the store
- onSet() Fired when a row's data is changed
- onSizeChange() Fired when the size of the grid model is changed
Methods
Returns gridx.core.model.__RowCache: The row cache
Get the row cache by row id
Parameter | Type | Description |
---|---|---|
id | String | The row ID |
Returns gridx.core.model.__RowCache: The row cache
Get the row cache by row index.
Parameter | Type | Description |
---|---|---|
index | Integer | The row index |
parentId | String | Optional. If parentId is valid, the row index means the child index under this parent. |
Returns Array: An array of row IDs
Get IDs of children rows.
Parameter | Type | Description |
---|---|---|
id | String | The row ID |
Unlock a row cache in memory, so that it could be cleared out when cache size is reached.
Parameter | Type | Description |
---|---|---|
id | String | Optional. The row ID. If omitted, all kept rows will be freed. |
Returns Boolean: Whether this row has child rows.
Check whether a row has children rows.
Parameter | Type | Description |
---|---|---|
id | String | The row ID |
Returns Integer: The row index
Transform row ID to row index
Parameter | Type | Description |
---|---|---|
id | String | The row ID |
Returns String: The row ID
Transform row index to row ID
Parameter | Type | Description |
---|---|---|
index | Integer | The row index |
parentId | String | Optional. If parentId is valid, the row index means the child index under this parent. |
Lock up a row cache in memory, avoid clearing it out when cache size is reached.
Parameter | Type | Description |
---|---|---|
id | String | The row ID |
Returns dojo.Deferred: If return true in this function, the scan process will end immediately.
Go through all the rows in several batches from start to end (or according to given args),
and execute the callback function for every batch of rows.
Parameter | Type | Description |
---|---|---|
args | Object | An object containing scan arguments |
callback | Function(rows,startIndex) | The callback function. |
Returns Integer: The count of (child) rows
Get the count of rows under the given parent.
Parameter | Type | Description |
---|---|---|
parentId | String | Optional. The ID of a parent row. No parentId means root rows. |
Returns String[]: An array of parent row IDs, from root to parent.
Root level rows have parent of id ""(empty string).
Get tree path of row by row ID
Parameter | Type | Description |
---|---|---|
id | String | The row ID |
Returns dojo.Deferred: A Deferred object indicating when all this process is finished. Note that in this Deferred object,
The needed rows might not be available since they might be cleared up to reduce memory usage.
This method makes it convenient to do various grid operations without worrying too much about server side or client side store. This method is the only asynchronous public method in grid model, so that most of the custom code can be written in synchronous way.
Parameter | Type | Description |
---|---|---|
args | Object|null | Optional. Indicate what rows are needed by listing row IDs or row indexes.
Acceptable args include:
1. A single row index.
e.g.: model.when(1, ...)
2. A single row index range object in form of: {start: ..., count: ...}.
If count is omitted, means all remaining rows.
e.g.: model.when({start: 10, count: 100}, ...)
3. An array of row indexes and row index ranges.
e.g.: model.when([0, 1, {start: 10, count: 3}, 100], ...)
4. An object with property "index" set to the array defined in 3.
e.g.: model.when({
index: [0, 1, {start: 10, count: 3}, 100]
}, ...)
5. An object with property "id" set to an array of row IDs.
e.g.: model.when({
id: ['a', 'b', 'c']
}, ...)
6. An object containing both contents defined in 4 and 5.
7. An empty object
The model will fetch the store size. Currently it is implemented by fetching the first page of data.
8. null or call this method without any arguments.
This is useful when we only need to execute pending data operations but don't need to fetch rows. |
callback | Function | Optional. The callback function is called when all the pending data operations are executed and all |
scope |