TreeGrid v6.0
Row and cell selecting
There can be more selected rows and cells in grid. Don’t confuse selected and focused row. The focused row is the only row with cursor (FRow).
By default can be selected only whole rows, to permit selecting of individual cells or cell ranges set <Cfg SelectingCells=’1’/>.
By default can be rows (and cells) selected by Ctrl+click, Shift+click, Space, Ctrl + drag, Panel Select click or drag.
To change default selecting behavior assign the selecting actions to different events.
By default is selection persistent. To clear selection after mouse click, add to action OnClickCell=”... ,ClearSelection”.
To permit only selected row at a time, add the ClearSelection before all selecting actions calls.
The selected rows can be deleted, moved or copied. They can be also sent to server.
The selected rows can be got by GetSelRows method and used for any custom task. To find out what cells are selected read Selected attribute of the cell.
<Cfg> bool Selecting [1] .
If selecting rows or cells is permitted.
To control how rows and cells can be selected by a user, assign the selecting actions to appropriate events.
By default is permitted selecting rows but not selecting cells <Cfg Selecting=’1’ SelectingCells=’0’/>.
<Cfg> bool SelectingCells [0] .
If selecting individual cells or cells ranges is permitted.
It is disabled by default!
<Cfg> bool SelectingText [0] .
If text selection in grid (standard browser behavior) by mouse is permitted.
To let a user to select text, there must also not any drag action possible for the cell, otherwise the drag action is done.
If it is 1, there can be unwanted selection blinking during grid dragging and selection actions!
<Cfg> bool SaveSelected [0] Saves information to cookies .
If set to 1, saves all Selected row ids to cookies. Therefore it remembers all Selected rows on the client.
Remember, cookies are limited to 4096 bytes for the whole page, so use this setting only for very small tables or use PersistentCfg.
Use also as small row ids as possible (the amount of cookie space is used: id+1 bytes per selected row).
<Cfg> bool CalculateSelected [0] .
If there are formulas in grid that use selected rows.
If set, all calculated rows are recalculated after selection changes
<I> bool CanSelect [1] .
If row can be selected.
If set to 0, the row cannot be selected by any method.
<C> bool CanSelect [1/0] new 7.1 .
If the individual cells in the column can be selected.
If set to 0, the column cells are excluded from selected ranges, but the whole row can be still selected.
Default value is 1 for all columns except Panel.
<Header> bool CanSelect [1] .
If the Panel SelectAll button is enabled. Header row itself can never be selected.
<I> int Selected [0] .
It is set to 1 when the row is selected. It is colored yellow (by default setting in Grid.css).
It is set to 2 when the row contains some but not all selected cells.
There can be more selected rows in the grid. Don’t confuse selected and focused row. The focused row is the only row with cursor.
<I cell> bool Selected [0] .
It is set to 1 when the cell is selected. In this case the row has Selected = 2.
<Panel> bool Select [1] .
If the default Panel button Select is visible. This button is hidden also if <Cfg Selecting=”0”/>. This button is inactive when the row has CanSelect=’0’.
Click to this button selects the whole row. Dragging this button selects rows range.
<Cfg> bool SelectClass [0] new 6.0 .
If set to 1, selected cells can be highlighted also by CSS class attributes like color or font, defined in GxColorSelected CSS class in Grid.css.
If set to 0, selected cells are highlighted only by background color.
It is used for SelectingCells, selected rows are always highlighted by CSS class.
The value 1 can slow down selecting cells.
API event void OnSelect (TGrid grid, TRow row, int deselect) upd 6.0 .
Called before the row is selected or unselected. Called before the selection state of the row is changed.
deselect is 0 if the row will be selected, 1 if will be unselected and 2 if some (but not last) cell will be selected or unselected.
API event bool OnSelectAll (TGrid grid) .
Called before all rows in grid are selected or unselected.
Return true to suppress the action.
API method TRow[] GetSelRows ( ) .
Returns all selected rows in JavaScript array. They are sorted according to their position in grid.
Returns also selected fixed rows (head rows on beginning and foot rows on end).
If SelectingCells is permitted, to find out what cells are selected read Selected attribute of the cell: if(row[col+”Selected”]) ...
API method void SelectRow (TRow row, bool select = null) upd 6.0 .
Selects / unselects whole row. Select the row if select = 1, unselects if select = 0.
If select = null and the row has at least one selected cell, it is unselected, otherwise it is selected.
API method void SelectAllRows (int select = null) upd 6.0 .
Selects / unselects all rows.
If select = 1 selects all rows, select = 0 unselects all rows, select = -1 invert all rows (every selected row will be unselected and vice versa)
If select = null and some row is selected, unselects all rows, otherwise it selects all rows.
API method [][] GetSelRanges ( ) new 7.0 .
Returns all selected rectangles in table.
Returns it in two dimensional array: [ [row11,col11,row12,col12],[row21,col21,row22,col22],[row31,col31,row32,col32],…]
API method void SelectRange (TRow row1, string col1, TRow row2, string col2, int select, int type) .
Selects rectangular range of cells, including given cells
If col1 is null, selects all rows in range row1 – row2 including, otherwise selects continuous range of cells between [row1,col1] [row2,col2].
The first point [row1,col1] need not be the top left point.
select = 0 – unselects range, 1 – selects range, 2 – unselects range if cell [row1,col1] is selected, otherwise selects the range.
type = bit array, &1 – selects only visible rows, &2 – ignores children of collapsed rows.
<Actions> SelectCells Not assigned to any event, can be assigned to OnDrag... events only .
Starts selecting rectangular range of cells by mouse dragging. Fails if Selecting or SelectingCells is 0.
<Actions> DeselectCells Not assigned to any event, can be assigned to OnDrag... events only .
Starts deselecting rectangular range of cells by mouse dragging. Fails if Selecting or SelectingCells is 0.
<Actions> SelectRows Not assigned to any event, can be assigned to OnDrag... events only .
Starts selecting range of rows by mouse dragging. Fails if Selecting is 0.
<Actions> DeselectRows Not assigned to any event, can be assigned to OnDrag... events only .
Starts deselecting range rows by mouse dragging. Fails if Selecting is 0.
<Actions> InvertCellsFirst Assigned to OnCtrlDragRow event, can be assigned to OnDrag... events only .
Starts selecting or deselecting rectangular range of cells by mouse dragging. Fails if Selecting or SelectingCells is 0.
If the actual cell is selected, starts deselecting, otherwise starts selecting.
<Actions> InvertRowsFirst Assigned to OnCtrlDragRow event, can be assigned to OnDrag... events only .
Starts selecting or deselecting range of rows by mouse dragging. Fails if Selecting is 0.
If the actual row is selected (at least one cell), starts deselecting, otherwise starts selecting.
<Actions> SelectOddRows Not assigned to any event, can be assigned to OnDrag... events only .
Starts selecting individual rows – every row under mouse cursor is selected. Fails if Selecting is 0.
<Actions> DeselectOddRows Not assigned to any event, can be assigned to OnDrag... events only .
Starts deselecting individual rows – every row under mouse cursor is deselected. Fails if Selecting is 0.
<Actions> InvertOddRows Assigned to OnDragPanelSelect event, can be assigned to OnDrag... events only .
Starts inverting selection of individual rows - every row under mouse cursor changes its selection state. Fails if Selecting is 0.
<Actions> SelectRow ...F Assigned to OnSpace, OnCtrlClickCell and OnClickPanelSelect events .
Selects actual or focused row. Fails if the row is already selected, cannot be selected or Selecting is 0.
<Actions> DeselectRow...F Assigned to OnSpace, OnCtrlClickCell and OnClickPanelSelect events .
Deselects actual or focused row. Fails if the row is not selected, cannot be selected or Selecting is 0.
To invert selection action use “SelectRow OR DeselectRow”
<Actions> SelectCell...F Assigned to OnCtrlClickCell event .
Selects actual or focused cell. Fails if the cell is already selected, row cannot be selected or Selecting or SelectingCells is 0.
<Actions> DeselectCell...F Assigned to OnCtrlClickCell event .
Deselects actual or focused cell. Fails if the cell is already selected, row cannot be selected or Selecting or SelectingCells is 0.
To invert selection action use “SelectCell OR DeselectCell”
<Actions> SelectCol...F Not assigned to any event .
Selects whole actual or focused column. Fails if all cells in the column are selected or cannot be selected or Selecting or SelectingCells is 0.
<Actions> DeselectCol...F Not assigned to any event .
Deselects whole actual or focused column. Fails if no cells in the column are selected or cannot be selected or Selecting or SelectingCells is 0.
To invert selection action use “SelectCol OR DeselectCol”
<Actions> SelectRowRange Not assigned to any event .
Selects all rows between focused row and actual row, including both rows. Fails if Selecting is 0.
<Actions> DeselectRowRange Not assigned to any event .
Deselects all rows between focused row and actual row, including both rows. Fails if Selecting is 0.
<Actions> InvertRowRangeFirst Assigned to OnShiftClickCell event .
Selects or deselects all rows between focused row and actual row, including both rows. Fails if Selecting is 0.
If the focused row is selected, deselects all, otherwise selects all
<Actions> SelectCellRange Not assigned to any event .
Selects all cells in rectangular range between focused cell and actual cell. Fails if Selecting or SelectingCells is 0.
<Actions> DeselectCellRange Not assigned to any event .
Deselects all cells in rectangular range between focused cell and actual cell. Fails if Selecting or SelectingCells is 0.
<Actions> InvertCellRangeFirst Assigned to OnShiftClickCell event .
Selects or deselects all cells in rectangular range between focused cell and actual cell. Fails if Selecting or SelectingCells is 0.
If the focused cell is selected, deselects all, otherwise selects all
<Actions> SelectAll Assigned to OnCtrlSpace and OnClickHeaderSelect events .
Selects all visible rows. Fails if all rows are selected or cannot be selected or Selecting is 0.
This action can be asynchronous!
<Actions> DeselectAll Assigned to OnCtrlSpace and OnClickHeaderSelect events .
Deselects all visible rows. Fails if no rows is selected or cannot be selected or Selecting is 0.
To always deselect all rows you should use ClearSelection instead!
This action can be asynchronous, so you should not call any other select actions after this in the same event!
<Actions> InvertAll Assigned to OnCtrlClickHeaderSelect events .
Inverts whole selection, unselects all visible selected rows and selects all unselected rows. Fails if Selecting is 0.
It is not the same as “SelectAll OR DeselectAll”!
<Actions> ClearSelection Not assigned to any event .
Clears whole selection, including hidden rows. It is always synchronous and never fails.
Add it to OnClickCell and OnClickOutside to clear selection after any click – to have not persistent selection.
For example <Actions OnClickCell=’ClearSelection,FocusEdit’ OnClickOutside=’ClearSelection,Blur’/>
To permit only selected row at a time, add it before all selecting actions calls.
A user can fill cell values by mouse dragging.
To permit it, just set <Actions OnDragCell=’FillCells’/> or similarly to different drag action, e.g <Actions OnCtrlDragCells=’FillCells’/>.
The first clicked cell value is used as source for all cells in rectangle selected by mouse.
By default the value of the first cell is just copied to the other cells. You can change this behavior by Use OnAutoFill and OnAutoFillValue events.
<Actions> FillCells Attached to OnShiftDragRow event, can be attached only to OnDrag... event .
Starts filling cell values by the actual cell value. It fills to all cells the focused cell value.
<Actions> FillCol Not attached to any event, can be attached only to OnDrag... event .
Starts filling cell values by the actual cell value. It fills only vertically.
<Actions> FillRow Not attached to any event, can be attached only to OnDrag... event .
Starts filling cell values by the actual cell value. It fills only horizontally.
API event bool OnAutoFill (TGrid grid, TRow r1, string c1, TRow r2, string c2, bool rdir, bool cdir) .
Called after cell range is selected by used in action FillCells/Row/Col, before the standard filling is done.
r1,c1,r2,c2 is the selected cell range. r1,c1 is always the firstly clicked cell.
rdir is vertical direction - 0 when r2 is under r1 and 1 if r2 is above r1.
cdir is horizontal direction - 0 when c2 is right from c1 and 1 when c2 is left from c1.
This function can be used to do to any operation in cell range created by dragging.
Return true to suppress default behavior. If returns true, the OnAutoFillValue is not called.
API event type OnAutoFillValue (TGrid grid, TRow row, string col, TRow orow, string ocol, type val, type prevval, int rowpos, int colpos) .
Called when automatically filling cell values selected by dragging in action FillCells/Row/Col, like in Excel.
It is called for every cell in the range to get its new value.
row, col is cell to fill; orow, ocol is base cell (the first cell dragged); val is predefined value to be filled.
prevval is previously filled (returned) value, for the base cell is null.
rowpos, colpos is distance from the actual cell from the base cell = base cell has 0,0. rowpos is negative when filling up and colpos when filling left.
Returns new value or val.
For example: Grids.OnAutoFillValue=function(G,row,col,orow,ocol,val,old,ri,ci){return val+ri+ci;} – fills with increased values right down and decreased top left.