Methods

This section describes the methods that can be used to manipulate the dxDataGrid widget.

addColumn(columnOptions)

Adds a new column to a grid.

Parameters:
columnOptions:

Object

|

String

The options of the added column or the name of a data field.

To add a column to a grid, call the addColumn(columnOptions) method of the grid instance. Pass the options of the added column as the columnOptions argument. Refer to the columns option description for the full list of available options.

There may be cases, when no options, except the dataField, are required to be specified. In this instance, pass the name of the data field as the argument to the addColumn(columnOptions) method instead of the object with column options.

beginCustomLoading(messageText)

Displays the load panel.

Parameters:
messageText:

String

Text to be displayed in the load panel.

Normally, dxDataGrid displays a load panel automatically when it is busy rendering or loading data. Additionally, the load panel can be invoked when required by calling the beginCustomLoading(messageText) method. If you call this method without the argument, the load panel displays text specified by the loadPanel | text option. To specify the appearance of the load panel, use the properties of the loadPanel configuration object.

Once invoked from code, the load panel will not hide until the endCustomLoading() method is called.

NOTE
The load panel invoked from code does not replace the automatically invoked load panel. This circumstance might lead to a situation where the load panel invoked from code suddenly changes its text because it was overridden by the automatically invoked load panel. Hence, be mindful when invoking the load panel with different text.

beginUpdate()

Prevents the component from refreshing until the endUpdate method is called.

The beginUpdate and endUpdate methods allow you to apply several modifications to the component. After the beginUpdate method is called, the component does not update the UI until the endUpdate method is called. The usage of these methods prevents excessive component updating when you are changing multiple component settings at once.

byKey(key)

Allows you to obtain a data object by its key.

Parameters:
key:

Object

|

String

|

Number

The key value of the required data object.

Return Value:

jQuery.Promise

A Promise of the jQuery.Deferred object resolved after the data object has been loaded.

The following code snippet demonstrates how to get a data object whose key equals 15.

JavaScript
dataGridInstance.byKey(15).done(function(dataObject) {
        // process 'dataObject'
    }).fail(function(error) {
        // handle error
    });

cancelEditData()

Discards changes made in a grid.

To learn how to manage the editing process from code, see the Editing in Code topic.

clearFilter()

Clears all the filters of a specific type applied to grid records.

Parameters:
filterName:

String

Type of filter to be cleared. Can be 'dataSource', 'search', 'header' or 'row'.

In dxDataGrid, grid records can be filtered in several different ways. This method's parameter specifies what type of filter should be cleared. The parameter values can be the following:

To clear all available filters, call this method without parameters.

View Demo

clearGrouping()

Ungroups grid records.

For more information about grouping, see the Grouping topic.

clearSelection()

Deselects all grid records.

Alternatively, you can deselect specific grid records using the deselectRows(keys) method.

View Demo

clearSorting()

Clears sorting settings of all grid columns at once.

For more information about sorting in dxDataGrid, see the Sorting topic.

closeEditCell()

Draws the cell being edited from the editing state. Use this method when the edit mode is batch.

To learn how to manage the editing process from code, see the Editing in Code topic.

collapseAll(groupIndex)

Collapses groups or master rows in a grid.

Parameters:
groupIndex:

Number

| undefined

The index of the groups to collapse. Pass undefined to collapse all groups. Pass -1 to collapse all master rows.

Learn more from the Expanding and Collapsing Groups topic.

NOTE
This method cannot be called if you use a remote data source.

collapseRow(key)

Allows you to collapse a specific group or master row by its key.

Parameters:
key: any

The key of the group or master row.

To collapse a group row, call this method with an array each member of which is a grouping value. To collapse a master row, pass its key to this method.

columnCount()

Returns the number of data columns in a grid.

Return Value:

Number

The number of data columns in a grid.

The columnCount() method returns the number of columns currently presented in a grid. This number includes visible and hidden columns, but omits the selection and editing columns.

columnOption(id)

Returns the options of a column by an identifier.

Parameters:
id:

Number

|

String

The name or index or data field or caption of a column.

Return Value:

Object

The options of the specified column.

Use this method to obtain an object of the options currently applied to a specific column. This method accepts one of the following.

  • Name
    The unique name of the column.

  • Column Index
    Equals the index of the column in the columns array.

  • Data Field
    The name of the data source field assigned to the column.

  • Caption
    The text displayed in the column header.

The options of the first column matching either the name or column index or data field or caption will be returned by this method.

For the list of options included in the object returned by the columnOption(id) method, refer to the columns option description. Additionally, you can get the value of a specific column option using the same method called with two arguments.

columnOption(id, optionName)

Returns the value of a specific column option.

Parameters:
id:

Number

|

String

The name or index or data field or caption of a column.

optionName:

String

The name of the required option.

Return Value: any

The value of the specified option.

Use this method to obtain the value of a specific column option. This method accepts one of the following as the first argument.

  • Name
    The unique name of the column.

  • Column Index
    Equals the index of the column in the columns array.

  • Data Field
    The name of the data source field assigned to the column.

  • Caption
    The text displayed in the column header.

The specified option of the first column matching either the name or column index or data field or caption will be returned by this method.

For the list of accessible options, refer to the columns option description. Additionally, you can get all options of a specific column by calling the same method with an identifier only.

columnOption(id, optionName, optionValue)

Sets an option of a specific column.

Parameters:
id:

Number

|

String

The name or index or data field or caption of a column.

optionName:

String

The name of the option to change.

optionValue: any

A new value for this option.

Using this method, you can set an option of a specific column from code. This method accepts one of the following as the first argument.

  • Name
    The unique name of the column.

  • Column Index
    Equals the index of the column in the columns array.

  • Data Field
    The name of the data source field assigned to the column.

  • Caption
    The text displayed in the column header.

The specified option of the first column matching either the name or column index or data field or caption will be changed by this method.

For the list of accessible options, refer to the columns option description. Also, you can set several column options at once. Use the columnOption(id, options) method to do this.

columnOption(id, options)

Sets several options of a column at once.

Parameters:
id:

Number

|

String

The name or index or data field or caption of a column.

options:

Object

The required configuration options.

Using this method, you can set several options of a specific column from code. This method accepts one of the following as the first parameter.

  • Name
    The unique name of the column.

  • Column Index
    Equals the index of the column in the columns array.

  • Data Field
    The name of the data source field assigned to the column.

  • Caption
    The text displayed in the column header.

The options of the first column matching either the name or column index or data field or caption will be changed by this method.

For the list of accessible options, refer to the columns option description. If you need to set only one option for a column, you can use the columnOption(id, optionName, optionValue) method instead.

defaultOptions(rule)

Specifies the device-dependent default configuration options for this component.

Parameters:
rule:

Object

An object specifying default options for the component and the device for which the options must be applied.

Object structure:
device:

Object

|

Array

|

Function

An object representing device parameters, or an array of objects representing device parameters, or a function that provides information on the current device as an input parameter and returning a Boolean value.

options:

Object

A configuration object with specified options.

The defaultOptions method is a static method supported by the widget class. The following code demonstrates how to specify default options for all buttons in the application executed on the iOS platform.

JavaScript
DevExpress.ui.dxButton.defaultOptions({ 
    device: { platform: "ios" },
    options: {
        text: "Click me"
    }
});

deleteColumn(id)

Removes the column from the grid.

Parameters:
id:

Number

|

String

The current column index or the name of the data field in the dataSource.

deselectAll()

Deselects the rows that are currently selected within the applied filter.

Alternatively, you can deselect all grid records at once using the clearSelection() method.

deselectRows(keys)

Deselects specific grid records.

Parameters:
keys:

Array

The keys of the records to be deselected.

To access a grid record by a key, a field providing key values must be specified in a data source. If no key was specified, the whole data object is considered the key.

Alternatively, you can deselect all grid records at once using the clearSelection() method.

editCell(rowIndex, dataField)

Sets a specific cell into the editing state.

Parameters:
rowIndex:

Number

The index of a row holding the cell that should enter the editing state.

dataField:

String

The data field associated with the cell that should enter the editing state.

To learn how to manage the editing process from code, see the Editing in Code topic.

editCell(rowIndex, visibleColumnIndex)

Sets a specific cell into the editing state.

Parameters:
rowIndex:

Number

The index of a row holding the cell that should enter the editing state.

visibleColumnIndex:

Number

The index within visible columns of a column holding the cell that should enter the editing state.

To learn how to manage the editing process from code, see the Editing in Code topic.

editRow(rowIndex)

Sets a specific row into the editing state.

Parameters:
rowIndex:

Number

The index of a row that should enter the editing state.

To learn how to manage the editing process from code, see the Editing in Code topic.

element()

Returns the root HTML element of the widget.

Return Value:

jQuery

The root element of the widget.

endCustomLoading()

Hides the load panel.

Normally, a load panel in dxDataGrid is hidden automatically when the widget is ready. But if you have invoked the load panel from code using the beginCustomLoading(messageText) method, you must call the endCustomLoading() method to hide it.

endUpdate()

Enables the component to refresh after the beginUpdate method call.

The beginUpdate and endUpdate methods allow you to apply several modifications to the component. After the beginUpdate method is called, the component does not update the UI until the endUpdate method is called. The usage of these methods prevents excessive component updating when you change multiple component setting at once.

expandAll(groupIndex)

Expands groups or master rows in a grid.

Parameters:
groupIndex:

Number

| undefined

The index of the groups to expand. Pass undefined to collapse all groups. Pass -1 to expand all master rows.

Learn more from the Expanding and Collapsing Groups topic.

NOTE
This method cannot be called if you use a remote data source.

expandRow(key)

Allows you to expand a specific group or master row by its key.

Parameters:
key: any

The key of the group or master row.

To expand a group row, call this method with an array (each member of which is a grouping value). To expand a master row, pass its key to this method.

exportToExcel(selectionOnly)

Exports grid data to Excel.

Parameters:
selectionOnly:

Boolean

Indicates whether to export all the data presented in the grid or the selected rows only.

For details on exporting, refer to the Export article.

filter()

Returns a filter expression applied to the grid's data source using the filter(filterExpr) method.

Return Value: any

You can get a total filter summarized from all possible filters:

For this purpose, use the getCombinedFilter() method.

filter(filterExpr)

Applies a filter to the grid's data source.

Parameters:
filterExpr: any

This method filters grid records in code. Pass an array with the following members to this method.

  1. The data source field by which data items are filtered.
  2. The comparison operator. The following operators are available: "=", "<>", ">", ">=", "<", "<=", "startswith", "endswith", "contains", "notcontains".
  3. The value with which data source field values should be compared.

The filters specified by end users using a filter row, a column's header filter or the search panel are applied to the data source that is already filtered using the filter(filterExpr) method. To clear all the filters applied to the grid both in code and by end users, call the clearFilter('dataSource') method.

See Also

For more information on how to apply a filter from code, refer to the Filtering in Code topic.

View Demo

focus()

Sets focus on the widget.

focus(element)

Focuses the specified cell element in the grid.

Parameters:
element:

jQuery

The cell element to be focused.

To get the element of the required cell, use the getCellElement(rowIndex, visibleColumnIndex) method, passing the column and row that identify the target cell.

getCellElement(rowIndex, dataField)

Allows you to obtain a cell by its row index and the data field of its column.

Parameters:
rowIndex:

Number

The row index of the cell.

dataField:

String

The data field of the cell's column.

Return Value:

jQuery

| undefined

The cell element; provides access to element-related jQuery operations.

getCellElement(rowIndex, visibleColumnIndex)

Allows you to obtain a cell by its row index and the visible index of its column.

Parameters:
rowIndex:

Number

The row index of the cell.

visibleColumnIndex:

Number

The visible index of the cell's column. Find out how to calculate this index in the Calculating the Column Index topic.

Return Value:

jQuery

| undefined

The cell element; provides access to element-related jQuery operations.

getCombinedFilter()

Returns a filter expression applied to the grid using all possible scenarious.

Return Value: any

dxDataGrid can be filtered both in code, using the filter(fitlerExpr) method, and in a UI, using a filter row, a column's header filter or the search panel. To get a total filter summarized from all the filters applied, use the getCombinedFilter() method.

getKeyByRowIndex(rowIndex)

Allows you to obtain the data key by a row index.

Parameters:
rowIndex:

Number

A row index.

Return Value: any

The data key of the row.

dxDataGrid's API comprises a great number of methods, some of which accept data keys as their arguments while the others accept row indexes. If you have a row index, you can obtain the respective data key by calling the getKeyByRowIndex(rowIndex) method. And vice versa as well, if you have a data key, you can obtain the respective row index by calling the getRowIndexByKey(key) method.

getRowIndexByKey(key)

Allows you to obtain the row index by a data key.

Parameters:
key:

Object

|

String

|

Number

The data key of a row in the store.

Return Value:

Number

The row index.

dxDataGrid's API comprises a great number of methods, some of which accept data keys as their arguments while the others accept row indexes. If you have a data key, you can obtain the respective row index by calling the getRowIndexByKey(key) method. And vice versa as well, if you have a row index, you can obtain the respective data key by calling the getKeyByRowIndex(rowIndex) method.

getSelectedRowKeys()

Gets the keys of currently selected grid records.

Return Value:

Array

The keys of the selected records.

If a field providing key values is not specified in a data source, the whole data object is considered the key. In this case, the getSelectedRowKeys() method returns data objects corresponding to the selected records, thus operating exactly as the getSelectedRowsData() method.

getSelectedRowsData()

Gets the data objects of currently selected grid records.

Return Value:

Array

The data objects of selected records.

To get only the keys of selected grid records, call the getSelectedRowKeys() method.

View Demo

getTotalSummaryValue(summaryItemName)

Gets the value of a total summary item.

Parameters:
summaryItemName:

String

The name of the total summary item.

Return Value: any

The automatically calculated value of the total summary item.

hideColumnChooser()

Hides the column chooser panel.

This method hides the column chooser panel. To invoke it from code, use the showColumnChooser() method.

insertRow()

Adds a new data row to a grid.

To learn more about how to insert a new row from code, see the Insertion paragraph of the Editing in Code topic.

instance()

Returns an instance of this component class.

Return Value:

Object

An instance of this component class

Use this method to access other methods of the component.

isRowExpanded(key)

Allows you to find out whether a specific group or master row is expanded or collapsed.

Parameters:
key: any

The key of the group or master row.

Return Value:

Boolean

true if the row is expanded; false if collapsed.

To find out whether a group row is expanded, call this method with an array, in which each member is a grouping value. To find out if a master row is expanded, pass its key to this method.

isRowSelected(key)

Allows you to find out whether a row is selected or not.

Parameters:
key: any

The key of the row.

Return Value:

Boolean

true if the row is selected; false otherwise.

keyOf(obj)

Returns the key corresponding to the passed data object.

Parameters:
obj:

Object

A data object.

Return Value: any

The key of the passed data object.

If a field providing key values is not specified in a data source, the whole data object is considered the key. In this case, the keyOf(obj) method returns its argument.

off(eventName)

Detaches all event handlers from the specified event.

Parameters:
eventName:

String

The name of the event to unsubscribe from.

Return Value:

Object

The object for which this method is called.

off(eventName, eventHandler)

Detaches a particular event handler from the specified event.

Parameters:
eventName:

String

The name of the event to unsubscribe from.

eventHandler:

Function

The handler to be detached from the specified event.

Return Value:

Object

The object for which this method is called.

on(eventName, eventHandler)

Subscribes to a specified event.

Parameters:
eventName:

String

The name of the event to be subscribed.

eventHandler:

Function

An event handler for the specified event.

Return Value:

Object

The object for which this method is called.

Use this method to subscribe to one of the events listed in the Events section.

See Also

on(events)

Subscribes to the specified events.

Parameters:
events:

Object

An object of the following structure: { "eventName1": handler1, "eventName2": handler2, ...}

Return Value:

Object

The object for which this method is called.

Use this method to subscribe to several events at one method call. Available events are listed in the Events section.

See Also

option()

Returns the configuration options of this component.

Return Value:

Object

An object representing the configuration options of this component.

option(optionName)

Gets the value of the specified configuration option of this component.

Parameters:
optionName:

String

The name of the option to get.

Return Value: any

The value of the specified option.

If you need to get the value of a configuration option field, specify the path to the required field.

option(optionName, optionValue)

Sets a value to the specified configuration option of this component.

Parameters:
optionName:

String

The name of the required option.

optionValue: any

The value you wish to assign to the required option.

To set a value to the configuration option field, specify the path to the required field.

option(options)

Sets one or more options of this component.

Parameters:
options:

Object

An object containing the required configuration options.

pageIndex()

Gets the index of the current page.

Return Value:

Number

The index of the current page.

When using the pager, this method returns a value that is one less than the number of the current page.

When using scrolling in a virtual or infinite mode, this method return the index of the page whose record is displayed first in the grid.

pageIndex(newIndex)

Switches a grid to a specified page.

Parameters:
newIndex:

Number

The index of the page to switch to.

This method allows you to switch between pages without using the pager or scrolling. Note that the page index, which is passed as the argument to the pageIndex(newIndex) method, is one number less than the page number.

pageSize()

Gets the current page size.

Return Value:

Number

The current page size.

To specify the page size when configuring the dxDataGrid widget, use the paging | pageSize property.

pageSize(value)

Sets the page size.

Parameters:
value:

Number

A new value of the page size.

To specify the page size when configuring the dxDataGrid widget, use the paging | pageSize property.

refresh()

Refreshes grid data.

When you use a data source that is changing dynamically, the dxDataGrid widget cannot automatically track changes that might be made in the source by a third party. In this case, to update data in the widget, call its refresh() method. Along with the main data source, a call of this method refreshes data sources of lookup columns if there are any in the grid.

NOTE
Calling the refresh() method concludes the editing process. In the row edit mode, all changes made in a row (if any) vanish. In the batch edit mode, changes are saved in a buffer waiting to be actually saved in the data source.

removeRow(rowIndex)

Removes a specific row from a grid.

Parameters:
rowIndex:

Number

The index of the row to be removed.

To learn more about how to remove a row from code, see the Removing paragraph of the Editing in Code topic.

repaint()

Redraws the widget.

After performing some external modifications that lead to a change of the widget container's size or visibility, the widget's state may become invalid. In this instance, use the repaint() method to redraw the widget.

saveEditData()

Saves changes made in a grid.

To learn how to manage the editing process from code, see the Editing in Code topic.

searchByText(text)

Searches grid records by a search string.

Parameters:
text:

String

A search string.

This method searches grid records by a search string. This string is searched in those grid columns that have the allowFiltering option set to true. To clear search results, call the searchByText(text) method with an empty string as the argument.

Additionally, a user might be able to search records using a search panel. The panel is hidden by default. To make it visible, assign true to the searchPanel | visible property.

selectAll()

Selects all grid records.

Use this method to select all grid records from code. To select records with specific keys, call the selectRows(keys, preserve) method. Additionally, you can specify options of user selection using properties of the selection configuration object.

View Demo

selectRows(keys, preserve)

Selects specific grid records.

Parameters:
keys:

Array

The keys of the records to be selected.

preserve:

Boolean

Specifies whether or not previously selected records must remain selected.

To access a grid record by a key, a field providing key values must be specified in a data source. If no key was specified, the whole data object is considered the key.

By default, calling the selectRows(keys, preserve) method deselects all previously selected records. If you need these records to remain selected, call the same method with true as its second argument as the code snippet below demonstrates.

JavaScript
dataGridInstance.selectRows([5, 10, 12], true);

View Demo

selectRowsByIndexes(indexes)

Selects grid rows by indexes.

Parameters:
indexes:

Array

The indexes of the rows to be selected.

An array, which is passed to this method as the argument, must contain row indexes. When calculating them, data and group rows are counted, though only data rows can be selected.

Note that selection applied by the selectRowsByIndexes(indexes) method will be cleared once the current page is changed. Therefore, to preserve the selection, call this method within the onContentReady callback function.

NOTE
Calling the selectRowsByIndexes(indexes) method deselects all previously selected records.

showColumnChooser()

Invokes the column chooser panel.

This method invokes the column chooser panel. To hide it from code, use the hideColumnChooser method.

state()

Returns the current state of the grid.

Return Value:

Object

An opaque data object representing the grid state.

For more information about working with the grid state, refer to the stateStoring option description.

state(state)

Sets the grid state.

Parameters:
state:

Object

An opaque data object representing the grid state.

For more information about working with the grid state, refer to the stateStoring option description.

totalCount()

Returns the number of records currently held by a grid.

Return Value:

Number

The number of records currently held by a grid.

Use this method to get the number of records currently held by a grid. Note that if records are filtered by a user using the filter row and search panel or from code using the filter(filterExpr) and searchByText(text) methods, the totalCount() method returns the number of records left after filtering.

undeleteRow(rowIndex)

Recovers a row deleted in the batch edit mode.

Parameters:
rowIndex:

Number

The index of the row to recover.

To learn more about how to recover a deleted row programmatically, see the Removing paragraph of the Editing in Code topic.

updateDimensions()

Updates the grid to the size of its content.

Use this method to update the position of grid contents after the grid element was resized.