I am using Dojo Dgrid however i am trying to add a checkbox column however i am not sure of the approach.
Most of the tutorials i have been looking at follow a different code structure and i am unable to create the check box column. I would like to create a checkbox column to select rows
Code (Here is also a Fiddle of my code)
require([
.......................
"dojo/domReady!"
], function(parser, declare, Grid, ColumnSet, Selection, selector,Keyboard, DijitRegistry){
parser.parse();
var data = [
{ first: "Tom", last: "Evans" },
{ first: "Sherry", last: "Young"},
{ first: "Bob", last: "William"}
];
var columns = [
[[
{editor({name: "CheckBox", field: "bool"}, "checkbox")},
{ field: "first", label: "First" },
{ field: "last", label: "Last" }]]
];
var CustomGrid = declare([Grid, ColumnSet, Selection, Keyboard, DijitRegistry]);
var grid = new CustomGrid ({
columnSets: columns ,
"class":"grid"
}, "grid");
grid.renderArray(data);
});
you can also test this solution
first you must add this Modules in require([]) section
then define this array to hold your columns
then add check box type column to array and any other type column to array
then define your Grid and set properties
and then you can get selected and deselected rows
and deselect
If you want to have a column with checkboxes for the purpose of selecting rows, you should set your sights on the
selector
column plugin rather thaneditor
.selector
is specifically designed to render checkboxes (or radio buttons) in each cell that ties in to theSelection
mixin when checked.See the documentation in the wiki, and the selector test page.