gridx
Legend: Array Boolean Constructor Date DomNode Error Function Namespace Number Object RegExp Singleton String

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

_addCmd
ParameterTypeDescription
args
_cmdRequest
_createExts
ParameterTypeDescription
exts
args
_exec
_execEvents
ParameterTypeDescription
scope
callback
_msg
_normArgs
ParameterTypeDescription
args
_onSizeChange
byId
Returns gridx.core.model.__RowCache: The row cache
Get the row cache by row id
ParameterTypeDescription
idStringThe row ID
byIndex
Returns gridx.core.model.__RowCache: The row cache
Get the row cache by row index.
ParameterTypeDescription
indexIntegerThe row index
parentIdString
Optional.
If parentId is valid, the row index means the child index under this parent.
children
Returns Array: An array of row IDs
Get IDs of children rows.
ParameterTypeDescription
idStringThe row ID
clearCache
constructor
ParameterTypeDescription
args
destroy
free
Unlock a row cache in memory, so that it could be cleared out when cache size is reached.
ParameterTypeDescription
idString
Optional.
The row ID. If omitted, all kept rows will be freed.
hasChildren
Returns Boolean: Whether this row has child rows.
Check whether a row has children rows.
ParameterTypeDescription
idStringThe row ID
idToIndex
Returns Integer: The row index
Transform row ID to row index
ParameterTypeDescription
idStringThe row ID
indexToId
Returns String: The row ID
Transform row index to row ID
ParameterTypeDescription
indexIntegerThe row index
parentIdString
Optional.
If parentId is valid, the row index means the child index under this parent.
isId
ParameterTypeDescription
id
keep
Lock up a row cache in memory, avoid clearing it out when cache size is reached.
ParameterTypeDescription
idStringThe row ID
parent
The parent ID.
Get the parent ID of the given row.
ParameterTypeDescription
idStringThe row ID
scan
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.
ParameterTypeDescription
argsObjectAn object containing scan arguments
callbackFunction(rows,startIndex)The callback function.
setStore
ParameterTypeDescription
store
size
Returns Integer: The count of (child) rows
Get the count of rows under the given parent.
ParameterTypeDescription
parentIdString
Optional.
The ID of a parent row. No parentId means root rows.
treePath
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
ParameterTypeDescription
idStringThe row ID
when
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.

ParameterTypeDescription
argsObject|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.
callbackFunction
Optional.
The callback function is called when all the pending data operations are executed and all
scope

Events

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