- Since:
- 5.0
Options
allowCopy :boolean
If true the selection can be copied to the clipboard using the browsers copy event.
Type:
- boolean
- Default Value:
- true
allowDelete :boolean
Only applies if editable is true. If false then can't use delete key to delete a row.
Type:
- boolean
- Default Value:
- true
allowEditMode :boolean
Only applies if editable is true. If false then can't go in or out of edit mode using mouse or keyboard.
Type:
- boolean
- Default Value:
- true
allowInsert :boolean
Only applies if editable is true. If false then can't use Insert key to add a row.
Type:
- boolean
- Default Value:
- true
columnSort :boolean
If true the mouse and keyboard can be used in column headings to adjust the sort order. The grid doesn't actually do any sorting. Something external to the grid must do the actual sorting by handling the sortchange event and updating the model.
Note the sort order can still adjusted external to the grid even if this is false.
Type:
- boolean
- Default Value:
- true
columnSortMultiple :boolean
If true multiple columns can be sorted using Shift key modifier. This only applys if columnSort is true.
Type:
- boolean
- Default Value:
- true
contextMenu :Object
A menu widget options object use to create the context menu.
Only specify one of contextMenu or contextMenuId and contextMenuAction. If none of contextMenu, contextMenuId or contextMenuAction are specified there is no context menu.
Type:
- Object
- Default Value:
- null
contextMenuAction :function
A callback function that is called when it is time to display a context menu. function( event ) The function is responsible for showing the context menu. It is given the event that caused this callback to be called.
In most cases it is simpler and more consistent to use the contextMenu option. Only specify one of contextMenu or contextMenuId and contextMenuAction. If none of contextMenu, contextMenuId or contextMenuAction are specified there is no context menu.
Type:
- function
- Default Value:
- null
contextMenuId :string
If option contextMenu is given then this is the element id to give the context menu created. This allows other code to interact with the created context menu widget.
If option contextMenu is not given then this is the element id of an existing menu widget.
Type:
- string
- Default Value:
- null
multiple :boolean
If true multiple rows can be selected otherwise only a single row can be selected.
Type:
- boolean
- Default Value:
- false
multipleCells :boolean
Only applies while selectCells is true. If true then a range of cells can be selected otherwise only a single cell is selected. The default is to allow a range of cells to be selected.
Type:
- boolean
- Default Value:
- true
reorderColumns :boolean
If true the mouse and keyboard can be used in column headings to reorder the columns or column groups.
Note the column order can still be changed external to the grid.
Type:
- boolean
- Default Value:
- true
resizeColumns :boolean
If true the mouse and keyboard can be used in column headings to adjust the width of columns.
Note the column widths can still be changed external to the grid.
Type:
- boolean
- Default Value:
- true
selectCells :boolean
When true select cells otherwise select rows. The default is to select rows.
Type:
- boolean
- Default Value:
- false
showNullAs :string
Text to display when the value is null or empty string
Type:
- string
- Default Value:
- "-"
stickyTop :boolean|function
Determine if the column header will stick to the top of the page as it scrolls.
Only applies if hasSize is false. If false the column header will not stick to the page. If true or a function the column header will stick to the top of the page using the stickyWidget If a function then it is passed to the stickyWidget as the top option.
Type:
- boolean | function
- Default Value:
- false
Events
selectionchange
Properties:
Name | Type | Description |
---|---|---|
event |
Event | jQuery event object. |
Examples
Initialize the grid with the selectionChange
callback specified:
$( ".selector" ).grid({
selectionChange: function( event ) {}
});
Bind an event listener to the gridselectionchange
event:
$( ".selector" ).on( "gridselectionchange", function( event ) {} );
Methods
activateRow(pCell, pCallback)
Parameters:
Name | Type | Description |
---|---|---|
pCell |
||
pCallback |
copyDownSelection(pColumnsopt, pCallbackopt)
Copies cell values from columns in the first selected row to all the other selected rows within the same columns. If pColumns is given only cells in the specified columns are copied down. Only cells that can be written will be copied to. If the selection mode is row selection, only visible columns that don't have noCopy column property equal true are filled.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pColumns |
array |
<optional> |
An optional array of column names to copy down. The columns must be in the selection, visible, and writable. |
pCallback |
function |
<optional> |
A no argument function that is called when the copy down operation is complete. |
debugCellEdit(value)
Parameters:
Name | Type | Description |
---|---|---|
value |
boolean |
Example
From the console
var view$ = ... // this is the grid widget jQuery object.
view$.grid("debugCellEdit", true)
// do your debugging
view$.grid("debugCellEdit", false)
fillSelection(pFillValue, pColumnsopt, pCallbackopt)
Fills all cells in the current selection with the value pFillValue. If pColumns is given only cells in the specified columns are filled. Only cells that can be written will be filled. If the selection mode is row selection, only visible columns that don't have noCopy column property equal true are filled.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pFillValue |
string | The value to fill cells with. | |
pColumns |
array |
<optional> |
An optional array of column names to fill. The columns must be in the selection, visible, and writable. |
pCallback |
function |
<optional> |
A no argument function that is called when the fill operation is complete. |
focus()
freezeColumn(pColumn)
Parameters:
Name | Type | Description |
---|---|---|
pColumn |
column name or column definition object to freeze. |
getActiveCellFromColumnItem(pItem) → {jQuery}
Parameters:
Name | Type | Description |
---|---|---|
pItem |
Element |
Returns:
- Type
- jQuery
getColumns() → {Array}
Returns:
- Type
- Array
getRecords(pRows) → {Array}
Parameters:
Name | Type | Description |
---|---|---|
pRows |
array of jQuery objects representing grid rows. |
Returns:
- Type
- Array
getSelectedRange() → {Object}
Properties:
Name | Type | Description |
---|---|---|
columns |
Array | An array of column names one for each selected column. The column name is null for the row header pseudo column. |
recordIds |
Array | An array of record ids one for each selected row. |
values |
Array | An array rows. Each row is an array of column values. |
Returns:
- Type
- Object
getSelectedRecords() → {Array}
Returns:
- Type
- Array
getSelection() → {Array}
Return the current selection. The return value depending on the selectCells option.
If selectCells is true, return the current selected range as an array of rows. Each row is a jQuery object containing the selected column cells.
If selectCells is false, return the currently selected rows as an array of jQuery objects each item in the array is a row. When there are frozen columns (or even just a frozen row header) each jQuery item in the array contains two tr elements. One for the frozen columns and one for the non-frozen columns.
Returns:
- Type
- Array
Examples
The following example processes a row selection (selectCells is false).
var i, rows = $( "#mygrid" ).grid( "getSelection" );
for ( i = 0; i < rows.length; i++ ) {
// note rows[i].length === 2 if there are frozen columns and 1 otherwise
rows[i].addClass("foo"); // this adds a class to both tr elements in the case where there are frozen columns
rows[i].children().each(function() {
// do something with each column
}
}
The following example processes a cell range selection (selectCells is true).
var i, rows = $( "#mygrid" ).grid( "getSelection" );
for ( i = 0; i < rows.length; i++ ) {
// note rows[i].length is the number of columns in the range selection.
rows[i].addClass("foo"); // this adds a class to all cells in the selected columns of this row
rows[i].each(function() {
// do something with each column cell
}
}
gotoCell(pRecordId, pColumnopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pRecordId |
string | the record id of the row to go to. | |
pColumn |
string |
<optional> |
column in the record row to go to. |
hideColumn(pColumn)
Parameters:
Name | Type | Description |
---|---|---|
pColumn |
column name or column definition object to hide. |
inEditMode() → {boolean}
Returns:
- Type
- boolean
moveColumn(pColumn, pNewPosition)
Parameters:
Name | Type | Description |
---|---|---|
pColumn |
column name or column definition object to move. | |
pNewPosition |
number | index into the array returned by getColumns where the column will be moved to. |
moveColumnGroup(pLevel, pOriginalPosition, pNewPosition)
Parameters:
Name | Type | Description |
---|---|---|
pLevel |
number | the level (starting with zero as the top most level) of the group |
pOriginalPosition |
number | original position of the column group |
pNewPosition |
number | new position of the column group |
refresh(pFocusopt)
Refreshes the grid with data from the model. This method is rarely needed because it is called automatically when the model changes, widget options change, or when pagination or column related methods are called.
Try to persist the selection. xxx What was selected may not exist in the grid after refresh. First try to select the same records.Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pFocus |
boolean |
<optional> |
if true put focus in the grid, if false don't. If undefined/omitted maintain focus if the grid already has focus. |
refreshColumns()
resize()
selectAll(pFocusopt, pNoNotifyopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pFocus |
boolean |
<optional> |
if true the first cell of the selection is given focus. |
pNoNotify |
boolean |
<optional> |
if true the selection change event will be suppressed |
setColumnWidth(pColumn, pWidth)
Parameters:
Name | Type | Description |
---|---|---|
pColumn |
column name or column definition object to set the width on. | |
pWidth |
number | width in pixels to set the column too. |
setEditMode(pEditMode)
Parameters:
Name | Type | Description |
---|---|---|
pEditMode |
boolean | If true enter edit mode if false enter navigation mode. |
setSelectedRecords(pRecords, pFocusopt, pNoNotifyopt) → {integer}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pRecords |
Array | array of data model records to select | |
pFocus |
boolean |
<optional> |
if true the first cell of the selection is given focus |
pNoNotify |
boolean |
<optional> |
if true the selection change event will be suppressed |
Returns:
- Type
- integer
setSelection(pRows, pFocusopt, pNoNotifyopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pRows |
Array | an array of jQuery row objects such as the return value of getSelection or a jQuery object containing one or more rows (tr elements) or columns (td elements) from this grid. xxx or array of jQuery column objects | |
pFocus |
boolean |
<optional> |
if true the first cell (in pRows) of the selection is given focus. |
pNoNotify |
boolean |
<optional> |
if true the selection change event will be suppressed |
showColumn(pColumn)
Parameters:
Name | Type | Description |
---|---|---|
pColumn |
column name or column definition object to show. |
unfreezeColumn(pColumn)
Parameters:
Name | Type | Description |
---|---|---|
pColumn |
column name or column definition object to unfreeze. |