Instead of feeding dojo.data sources to the grid, you may feed it a two-dimensional array. This approach works well for grids with fixed data, e.g. static reference tables. Here's an example culled from the unit test /dojoroot/dojox/grid/tests/test_grid.html. Note the following:
You can watch for changes to cells at the model level. This is called setting an observer and it followed the familiar Observer Design Pattern. With array-fed Grids, these are your only hook-in points for sending XHR back to the server. As we saw in Events, you can use dojo.Data's notification API, or the Observer API for the same thing.
To observe a model, you first create an object literal with function properties. These functions must be named:
For example, this observer watches all model changes and updates a visible row count.
var modelObservers = {
modelChange:function(){
dojo.byId("rowCount").innerHTML = 'Row count: ' + model.count;
}
}
Then you register the observer with the model:
model.observer(modelObservers);
|
dojox.grid.data.Model
The raw data behind a grid. Can be retrieved from a grid by accessing the
grid's public 'model' attribute. The model can be set for a grid by calling
setModel(newModel).
|
||
|
Properties
|
||
| clientSort | Boolean | User is allowed to sort by clicking column headers (dojo.data models only) |
| count | Integer | Number of rows currently in the model |
| query | Object | dojo.data query for current store (dojo.data stores only) |
| rowsPerPage | Integer | Rows to scroll down before another set of rows is rendered. |
| store | String | dojo.data store variable (dojo.data stores only) |
| updating | Integer | Number of rows in an UPDATING state |
|
Methods
|
||
| String getDatum(/* Integer */inRowIndex, /* Integer */inColIndex) | Return data at the location. Column indexes are id's for dojo.data models, integers for array models. | |
| Integer getColCount() | Return number of columns | |
| Object getRow(/* Integer */inRowIndex) | Returns item for dojo.data elements, array for array-based elements, at inRowIndex | |
| Integer getRowCount() | Returns number of rows in model | |
| notObserver(/* Object */ inObserver) | De-register an observer. | |
| observer(/* Object */ inObserver, /* String */inPrefix) | Register an observer object with the model. inPrefix is added to each function name before calling, as in myPrefixModelChange. That way you can specify multiple observers in the same object. | |
| Integer pageToRow(/* Integer */inPageIndex) | Starting row number on given page | |
| Integer rowToPage(/* Integer */inRowIndex) | Return page number for this row | |
| setDatum(/* Object */inDatum, /* Integer */inRowIndex, /* Integer */inColIndex) | Set the data at the given position. Normally called by cell editing. | |
| setRow(/* Object */inRow,/* Integer */inRowIndex) | Overwrite the row at the given index. Row must be in same object format as other rows, e.g. an item for dojo.data models or array for array models. | |
| swap(/* Integer */inIndexA, /* Integer */inIndexB) | Swap rows A and B in model. | |