Selection in Grid is enabled by default, and the user can select some row by a single click.
The library provides the following API to support selection in Grid:
Methods
Events
Related sample: Using Grid API Methods
When a cell is being selected, the grid automatically selects the row that this cell belongs to. On the other hand, in any selected row you have such an area as the selected cell which is:
So anytime you have a selection in the grid - you have 2 selection objects: a row and a cell.
When may you need to know the selected cell? For example, to detect which cell the user has clicked exactly or to open the editor for a specific cell.
To enable multiselect in the grid, call the enableMultiselect method:
Enabling multiselection
mygrid = new dhtmlXGridObject("gridbox");
mygrid.setImagePath("../../codebase/imgs/");
mygrid.setHeader("Sales,Book Title,Author,Price,In Store,Shipping");
mygrid.enableMultiselect(true); mygrid.init();
Related sample: Operations with clipboard
Users need to use Shift and Ctrl keys to select multiple rows.
The library has 2 extension modes that provide alternative types of selection in the grid.
Note, API related to the default selection can't be used with the alternative types (as alternative types are not really a selection, they are just marking.
The Block Selection mode is used to provide the support for clipboard operations. It allows selecting cells by blocks for copying data to the clipboard. Read more information on working with the clipboard in the Clipboard Operations article.
To enable the mode, call the enableBlockSelection method:
mygrid = new dhtmlXGridObject("gridbox");
mygrid.setImagePath("../../codebase/imgs/");
mygrid.setHeader("Sales,Book Title,Author,Price,In Store,Shipping");
mygrid.enableBlockSelection(); mygrid.init();
Related sample: Copy to clipboard
dhtmlxGrid provides an extension "markers" (dhtmlxgrid_markers.js) that enables the possibility to select cells instead of rows in the grid.
To enable selecting by cells in the grid, call the enableMarkedCells method:
mygrid = new dhtmlXGridObject("gridbox");
mygrid.setImagePath("../../codebase/imgs/");
mygrid.setHeader("Sales,Book Title,Author,Price,In Store,Shipping");
mygrid.enableMarkedCells();(); mygrid.init();
To mark a cell, use the mark method (the method invokes the onCellMarked event):
//marks a cell
mygrid.mark('row1',0,true);
//unmarks a cell
mygrid.mark('row1',0,false);
To unmark all marked cells, use the unmarkAll method (the method invokes the onCellUnMarked event):
//marks cells
mygrid.mark('row1',0,true);
mygrid.mark('row2',0,true);
//unmarks all cells
mygrid.unmarkAll();
To get all marked cells, use the getMarked method:
mygrid.getMarked();
To disable selection, return false from the onBeforeSelect event's handler:
myGrid.attachEvent("onBeforeSelect", function(row,old_row){
return false;
});
Back to top