data store as input.
eg.
var store = new ObjectStore(
{
"objectStore": new Memory(
{
"data": data.caseHistories.items
})
});
grid.setStore(store);
Formatting
The "structure" property which defines columns, has a field called formatter that is
supplied as a function that takes the data value as a parameter.
Before going further, let us re-iterate where the formatter function is defined. It is defined within a
structure column definition and hence it has peer fields which include "field". The "field" property
names the field within the array of objects (data) that is used for sourcing the value for the cell. It is
the value of the data object's property contained in the "field" attribute that is passed to the
formatter function.
As an alternative to supplying a single "field" name, we can supply an array of field names. In this
case, the parameter passed to the formatter function will be an array of values.
Finally, we can define the field name as the magic value "_item" and in this case the complete
object corresponding to the row will be passed to the formatter function.
The function must return an HTML string that will be displayed in the cell.
{
field: "Failure",
name: "Status",
width: "100px",
formatter: function(didFail)
{
if (didFail == false)
{
return "<img src='images/ok.png' />";
}
return "<img src='images/fail.png' />";
}
}
As an alternative to returning HTML string, we can also return a Dijit Widget:
See also:
• Sitepen - Populating your Grid using dojo/data – 1.7
Sorting columns
A function is defined on the DataGrid called "canSort(columnIndex)" which returns true or false. If
it returns true, then the column is sortable otherwise it is not. Make sure that you realize that the
Page 178
Comentarios a estos manuales