The model of a Grid control is an instance of a class, that implements the GridModel interface and contains the following key information:
The ArrayModel class uses an array of objects as a backing store, and an array of GridColumn instances as columns configuration data. Additionally, the name of the unique key field should be specified via the keyField parameter in the constructor. It will serve as a primary key to ensure proper functionality when sorting is applied to the grid.
The GridColumn class comprises the information that should be defined for all grid columns:
The data types, that can be specified for a column are String, Integer, RealNumber, Date, DateTime, Currency, Image and Lookup. A special type of column is the CommandType. Command columns do not display data, but an HTML element, that triggers a command action on some event.
The code below shows how to setup a Grid's model:
JavaScript Copy Code |
---|
var data = [ var column0 = new dv.GridColumn("ID"); var column1 = new dv.GridColumn("Name"); grid.model = new dv.ArrayModel(data, [column0, column1], "ID"); |
The metaData property of the GridColumn class provides a dictionary, which can store additional configuration data for that column, like lookup list for the LookupType, commands list for the CommandType and customEditor options for the Date, DateTime and Image types, as well as Intl formatting options and locales. Column metaData is also accessible
through the model's columnMetaData(columnIndex) method. Some examples of metaData usage:
JavaScript Copy Code |
---|
// a list of commands is expected to be provided for the CommandType column |