Is it possible to use a Dojo dgrid widget backed by an array (as opposed to a datastore) with checkboxes to select rows?
I successfully started with a basic array-backed dgrid, then added the Selection mixin to enable row selection. So now I have a dgrid that is backed by an array and allows row selection. However, when I try to add checkboxes via the selector column plugin, I get an error: this.store is undefined.
I determined this.store is used to identify which rows are selected: there are several calls to the this.store.getIdentity(rowObject) method which directly correlates to results returned when querying the grid's selection.
When using an array of objects instead of a store, is it possible specify a certain column field for identifying the selected rows? The WORKAROUND_STORE in my code below effectively does this, but perhaps I'm missing a simple solution like setting some property such as: selector({idProperty: 'col1'}).
It seems like it should be easier to do.
require(["dgrid/Grid",
"dgrid/selector",
"dgrid/Selection",
"dojo/_base/declare"],
function(Grid, selector, Selection, declare){
var columns = {
col1: selector({}),
col2: {label: 'COL2'},
col3: {label: 'COL3'},
};
var data = [
{ col1: '1', col2: 'A', col3: 'I'},
{ col1: '2', col2: 'B', col3: 'II'},
{ col1: '3', col2: 'C', col3: 'III'}
];
WORKAROUND_STORE = {
getIdentity: function(item) { return item.col1 }
}
var SelectionGrid = declare([Grid, Selection]);
window.methodGrid = new SelectionGrid({
store: WORKAROUND_STORE,
columns: columns,
selectionMode: "none",
allowSelectAll: true
}, "methodGridDiv");
window.methodGrid.renderArray(data);
}
);