Events
FastGrid documentation
Mouse events
Actions bool
On{Prefix}Click{Target}
(Grid Grid, Row Row, Col Col, Event Event)
GetTagAttr SetTagAttr
Called on click to grid. The handler is set in
Actions tag attribute as JavaScript code in string (e.g.
OnClick: "alert('Clicked '+(Row&&Row.id)+','+(Col&&Col.id))") or as function(Grid,Row,Col,Event){...}, e.g.
OnClick: function(Grid,Row,Col,Event){ alert('Clicked '+(Row&&Row.id)+','+(Col&&Col.id)); }.
{Prefix} is key prefix and / or mouse button name.
It can be
Shift /
Ctrl /
Alt /
Meta /
Right /
Middle or they combination in this order, e.g.
OnShiftRightClick: "alert('click')".
Left mouse button is without prefix by default.
The prefix names are defined in
Actions tag, attributes
ShiftPrefix,
CtrlPrefix,
AltPrefix,
MetaPrefix,
LeftPrefix,
RightPrefix,
MiddlePrefix.
{Target} is event target or Button name, there are four steps called in this order:
a)
Tool for toolbar cell or
Cell for normal cell or
Disabled for
Disabled cell or toolbar cell.
b)
empty for any click.
c)
button for clicked
Button name or one of predefined icon and button names listed below. It is ignored if empty.
d)
Any for any click.
Predefined button names for {Target} c):
Cells: Link (attribute
Link),
Date (Type
Date),
Bool (Type
Bool),
Cell icons: List,
Check,
Filter,
SelectRow,
SelectRows,
SelectCol,
SelectCols,
DeleteRow,
DeleteRows,
DeleteCol,
DeleteCols,
AddRow,
AddRows,
AddCol,
AddCols,
CollapseRow,
CollapseCol,
CollapseRowLevel (cell buttons for
LevelsPart),
Sort icons: SortVert (sort icon in header row for
SortIcons<=2),
SortUp (sort up in header row),
SortDown (sort down in header row),
SortHorz (sort icon in header column for
SortIcons<=2),
SortLeft (sort left in header column),
SortRight (sort right in header column),
Tool icons: all toolbar cells with
D Icon have predefined
Button as the cell
id,
Other: Image (image in
Images),
FocusEdge (edge of focus cursor),
FocusCorner (corner in focus cursor),
FocusAll (top left grid corner),
CollapseColLevel (Levels button in Tree column part),
CollapseCol (expand / collapse button in Tree column part),
The order of calling the event handlers:
OnPrefixClickTool or
OnPrefixClickCell in cell and next in Actions,
OnPrefixClick in cell and next in Actions,
OnPrefixClickButton in cell and next in Actions,
OnPrefixClickAny in cell and next in Actions,
OnClickTool or
OnClickCell in cell and next in Actions,
OnClick in cell and next in Actions,
OnClickButton in cell and next in Actions,
OnClickAny in cell and next in Actions.
For
Disabled cell there are called only:
OnPrefixClickDisabled in cell and next in Actions,
OnClickDisabled in cell and next in Actions.
The default actions are assigned to Actions tag in
Defaults.js.
By default it is called also for pressing keys Enter and Space, because their default assigned handler calls action ClickButton.
Cell, Tool bool
On{Prefix}Click{Target}
(Grid Grid, Row Row, Col Col, Event Event)
GetAttr SetAttr
Called on click to the grid cell or toolbar cell. The handler can be set as the row, column, cell, toolbar or toolbar cell attribute as JavaScript in string or function, see Actions
OnClick.
It is called after API
OnClick, but before Actions
OnClick, during processing the event. Return true to cancel the event and stop its propagation.
The
{Prefix} and
{Target} are the same as in the Actions
OnClick.
API event bool
OnClick
(Grid grid, Row row, Col col, int x, int y, Event event, string prefix)
Called on click to grid cell or any other grid part except some parts of scrollbar.
It is called before the event is processed. Return true to cancel the event and stop its propagation.
Row is clicked row or toolbar. It can be null if clicked outside cells.
Col is clicked column or toolbar cell. It can be null if clicked outside cells.
x,
y is click position inside cell.
Event is FastGrid event with various information. The original DOM mouse event is accessible by
event.Event.
prefix is set for pressed Shift/Ctrl/Alt/Meta keys as their names and for other mouse buttons /Right/Middle (for left mouse button is empty by default),
for more key or button prefixes they are joined in this order, e.g. "ShiftCtrlRight".
Actions bool
On{Prefix}DblClick{Target}
(Grid Grid, Row Row, Col Col, Event Event)
GetTagAttr SetTagAttr
Called on double click to grid. The handler is set in
Actions tag attribute as JavaScript code in string (e.g.
OnDblClick: "alert('Double clicked '+(Row&&Row.id)+','+(Col&&Col.id))") or as function(Grid,Row,Col,Event){...}, e.g.
OnDblClick: function(Grid,Row,Col,Event){ alert('Double clicked '+(Row&&Row.id)+','+(Col&&Col.id)); }.
It is not called if the OnClick event was processed and cancelled by some successfull event handler.
The
{Prefix} and
{Target} are the same as in the Actions
OnClick.
Cell, Tool bool
On{Prefix}DblClick{Target}
(Grid Grid, Row Row, Col Col, Event Event)
GetAttr SetAttr
Called on double click to the grid cell or toolbar cell. The handler can be set as the row, column, cell, toolbar or toolbar cell attribute as JavaScript in string or function, see Actions
OnDblClick.
It is called after API
OnDblClick, but before Actions
OnDblClick, during processing the event. Return true to cancel the event and stop its propagation.
It is not called if the OnClick event was processed and cancelled by some successfull event handler.
The
{Prefix} and
{Target} are the same as in the Actions
OnClick.
API event bool
OnDblClick
(Grid grid, Row row, Col col, int x, int y, Event event, string prefix)
Called on double click to grid cell or any other grid part except some parts of scrollbar.
It is not called if the OnClick event was processed and cancelled by some successfull event handler.
It is called before the event is processed. Return true to cancel the event.
Parameters are the same as
OnClick.
Actions bool
On{Prefix}Drag{Target}
(Grid Grid, Row Row, Col Col, Event Event)
GetTagAttr SetTagAttr
Called on start dragging in grid. The handler is set in
Actions tag attribute as JavaScript code in string (e.g.
OnDrag: "console.log('Start dragging '+(Row&&Row.id)+','+(Col&&Col.id))") or as function(Grid,Row,Col,Event){...}, e.g.
OnDrag: function(Grid,Row,Col,Event){ console.log('Start dragging '+(Row&&Row.id)+','+(Col&&Col.id)); }.
It is not called if the OnClick event was processed and cancelled by some successfull event handler.
The
{Prefix} and
{Target} are the same as in the Actions
OnClick.
Cell, Tool bool
On{Prefix}Drag{Target}
(Grid Grid, Row Row, Col Col, Event Event)
GetAttr SetAttr
Called on start dragging in the grid cell or toolbar cell. The handler can be set as the row, column, cell, toolbar or toolbar cell attribute as JavaScript in string or function, see Actions
OnDblClick.
It is called after API
OnDrag, but before Actions
OnDrag, during processing the event. Return true to cancel the event and stop its propagation.
It is not called if the OnClick event was processed and cancelled by some successfull event handler.
The
{Prefix} and
{Target} are the same as in the Actions
OnClick.
API event bool
OnDrag
(Grid grid, Row row, Col col, int x, int y, Event event, string prefix)
Called on start dragging grid cell or any other grid part except some parts of scrollbar.
It is called before special dragging events like
OnStartDrag.
It is called before the event is processed. Return true to cancel the event.
Parameters are the same as
OnClick.
Key events
Called on key down of key
{Target}. The
{Target} is the key name defined in
Actions tag in
KeyCodes, by default in
Defaults.js, e.g.
OnEnter or
OnCtrlK.
Predefined key names by their key codes:
Space: 32,
Enter: 13,
Esc: 27,
Backspace: 8,
Tab: 9,
CapsLock: 20,
ScrollLock: 145,
NumLock: 144,
Tilde: 192,
Minus: 189,
Equal: 187,
Backslash: 220,
LeftBracket: 219,
RightBracket: 221,
Semicolon: 186,
Apostrophe: 222,
Comma: 188,
Point: 190,
Slash: 191,
F1: 112,
F2: 113,
F3: 114,
F4: 115,
F5: 116,
F6: 117,
F7: 118,
F8: 119,
F9: 120,
F10: 121,
F11: 122,
F12: 123,
Ins: 45,
Del: 46,
Home: 36,
End: 35,
PageUp: 33,
PageDown: 34,
Up: 38,
Down: 40,
Left: 37,
Right: 39,
Pause:19,
NumDivide: 111,
NumStar: 106,
NumMinus: 109,
NumPlus: 107,
NumPoint: 110,
Num0: 96,
Num1: 97,
Num2: 98,
Num3: 99,
Num4: 100,
Num5: 101,
Num6: 102,
Num7: 103,
Num8: 104,
Num9: 105
{Prefix} is key prefix.
It can be
Shift /
Ctrl /
Alt /
Meta or they combination in this order, e.g.
OnShiftCtrlEnter: "alert('pressed enter')".
The prefix names are defined in
Actions tag, attributes
ShiftPrefix,
CtrlPrefix,
AltPrefix,
MetaPrefix.
The default actions are assigned to Actions tag in
Defaults.js.
Return true to suppress default action for the key event.
Cell, Tool bool
On{Prefix}{Target}
(Grid Grid, Row Row, Col Col, Event Event)
GetAttr SetAttr
Called on key down when the cell has focus (focused cell can be got by
GetFocus).
It is called after API
OnKeyDown, but before Actions
On{Prefix}{Target}, during processing the event. Return true to cancel the event and stop its propagation.
The
{Prefix} and
{Target} are the same as in Actions
On{Prefix}{Target}.
API event bool
OnKeyDown
(Grid grid, int key, Event event, string name, string prefix)
Called on key down when grid has focus.
It is called before the event is processed. Return true to cancel the event.
Grid receives focus on click or when calling
SetFocus or
SetFocused API methods.
key is DOM key event keyCode.
event is FastGrid key event. The original DOM mouse event is accessible by
event.Event.
name is FastGrid key name defined in
Actions.KeyCodes. If the
key has not assigned name, the
name is character from
key unicode.
prefix is set for pressed Shift/Ctrl/Alt/Meta keys as their names, for more key prefixes they are joined in this order, e.g. "ShiftCtrlMeta".
API events
API events are user defined JavaScript methods called from FastGrid code in various situations. Every API event has defined its specific parameters.
The individual API events are described in various places in the documentation, along with the related features.
This paragraph descibes defining and assigning API event handlers.
FastGrid
API event handlers can be assigned in three ways:
1) Defined in input JSON in tag
Events like:
Events:{ OnClick: function(Grid,row,col,X,Y){ alert("Clicked "+row.id+","+col.id) } }
2) Directly set in JavaScript to global
FGrid object like:
FGrid.OnClick = function(Grid,row,col,X,Y){ alert("Clicked "+row.id+","+col.id); }
3) Assigned in JavaScript by API method
AddEvent like:
grid.AddEvent("OnClick",function(Grid,row,col,X,Y){ alert("Clicked "+row.id+","+col.id));
These ways must not be combined for the same event!
Grid method string / int
AddEvent
(string event, function func, string ident = null)
Adds function
func as hander for
event.
For example:
grid.AddEvent("OnClick",function(Grid,row,col,X,Y){ alert("Clicked "+row.id+","+col.id),1);
ident is the handler custom unique identifier. If there was already added handler for the
event with the same
ident, the old handler is removed.
If the
ident is null, it adds the handler under new unique identification and returns the identification.
Returns the
ident or null if input parameters are incorrect. It does
not check if the
name is valid FastGrid event name.
It cannot add event handler if it is already assigned in Events in JSON or directly in FGrid.
Grid method bool
DelEvent
(string event, string ident = null)
Deletes event handler added by
AddEvent with the same
event and
ident.
If
ident is null, removes all handlers for the
event.
Returns true for success and false if there was no such handler to remove.
It can delete event handlers defined by any of the three ways described above.
Grid method void
DisableEvent
(string event)
Temporary removes all handlers added for given
event.
It can disable event handlers defined by any of the three ways described above.
Grid method void
EnableEvent
(string event)
Enables the event handlers temporary disabled by the
DisableEvent.