Angular DataGrid Methods
addColumn(columnOptions)
The column's configuration or the data field for which the column should be created.
This method is intended to add columns at runtime. To add columns at design-time, use the columns array.
If stateStoring is enabled, the added column is saved in the UI component's state after the creation.
See Also
addRow()
Use this method if you want to add an empty row. If you need to add a row with data, do the following:
For a remote data source, insert a new row with data into it and reload the data source:
jQuery
JavaScript$(function(){ var dataGrid = $("#gridContainer").dxDataGrid({ // ... }).dxDataGrid("instance"); var dataSource = dataGrid.getDataSource(); dataSource.store().insert(data).then(function() { dataSource.reload(); }) });
Angular
app.component.tsapp.module.tsimport { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { constructor() { this.dataSource = new DataSource({ // ... }) } // ... insertRowRemote: function(dataObj) { this.dataSource.store().insert(dataObj).then(function() { this.dataSource.reload(); }) } }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxDataGridModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxDataGridModule ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
App.vue<template> <DxDataGrid :data-source="dataSource" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxDataGrid from 'devextreme-vue/data-grid'; import DataSource from 'devextreme/data/data_source'; const ds = new DataSource({ // ... }); export default { components: { DxDataGrid }, data() { return { dataSource: ds } }, methods: { insertRowRemote: function(dataObj) { ds.store().insert(dataObj).then(() => ds.reload()); } } } </script>
React
App.jsimport React from 'react'; import 'devextreme/dist/css/dx.light.css'; import DataGrid from 'devextreme-react/data-grid'; import DataSource from 'devextreme/data/data_source'; const ds = new DataSource({ // ... }); class App extends React.Component { insertRowRemote(dataObj) { ds.store().insert(dataObj).then(() => ds.reload()); } render() { return ( <DataGrid dataSource={ds} /> ); } } export default App;
For a local data source, push a new row into it.
jQuery
JavaScript$(function(){ var dataGrid = $("#gridContainer").dxDataGrid({ // ... }).dxDataGrid("instance"); var dataSource = dataGrid.getDataSource(); dataSource.store().push([ { type: "insert", data: data } ]) });
Angular
app.component.tsapp.module.tsimport { Component } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { constructor() { this.dataSource = new DataSource({ // ... }) } // ... insertRowLocal: function(dataObj) { this.dataSource.store().push([ { type: "insert", data: dataObj } ]) } }
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxDataGridModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxDataGridModule ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
App.vue<template> <DxDataGrid :data-source="dataSource" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxDataGrid from 'devextreme-vue/data-grid'; import DataSource from 'devextreme/data/data_source'; const ds = new DataSource({ // ... }); export default { components: { DxDataGrid }, data() { return { dataSource: ds } }, methods: { insertRowLocal: function(dataObj) { ds.store().push([ { type: "insert", data: dataObj } ]); } } } </script>
React
App.jsimport React from 'react'; import 'devextreme/dist/css/dx.light.css'; import DataGrid from 'devextreme-react/data-grid'; import DataSource from 'devextreme/data/data_source'; const ds = new DataSource({ // ... }); class App extends React.Component { insertRowLocal(dataObj) { ds.store().push([ { type: "insert", data: dataObj } ]); } render() { return ( <DataGrid dataSource={ds} /> ); } } export default App;
This method works only when paging.enabled is false or when dataSource.reshapeOnPush is true and remoteOperations is false
See Also
- editing.allowUpdating
beginCustomLoading(messageText)
Shows the load panel.
Normally, the load panel is invoked automatically while the UI component is busy rendering or loading data. Additionally, you can invoke it by calling this method. If you call it without the argument, the load panel displays text specified by the loadPanel.text property. To specify the appearance of the load panel, use the loadPanel object. Once invoked from code, the load panel will not hide until you call the endCustomLoading() method.
See Also
beginUpdate()
Prevents the UI component from refreshing until the endUpdate() method is called.
The beginUpdate() and endUpdate() methods prevent the UI component from excessive updates when you are changing multiple UI component settings at once. After the beginUpdate() method is called, the UI component does not update its UI until the endUpdate() method is called.
See Also
byKey(key)
A Promise that is resolved after the data object is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.
The following code shows how to get a data object whose key is 15.
widgetInstance.byKey(15).done(function(dataObject) { // process "dataObject" }).fail(function(error) { // handle error });
See Also
cellValue(rowIndex, dataField)
The index of the row to which the cell belongs. Refer to Column and Row Indexes for more information.
The data field, caption, or unique name of the column to which the cell belongs.
cellValue(rowIndex, dataField, value)
The index of the row to which the cell belongs. Refer to Column and Row Indexes for more information.
The data field, caption, or unique name of the column to which the cell belongs.
Call saveEditData() after this method to save the changes:
jQuery
var dataGrid = $("#dataGridContainer").dxDataGrid("instance"); dataGrid.cellValue(0, "Position", "CEO"); dataGrid.saveEditData();
Angular
import { ..., ViewChild } from "@angular/core"; import { DxDataGridModule, DxDataGridComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxDataGridComponent, { static: false }) dataGrid: DxDataGridComponent; // Prior to Angular 8 // @ViewChild(DxDataGridComponent) dataGrid: DxDataGridComponent; updateCell(rowIndex, dataField, value) { this.dataGrid.instance.cellValue(rowIndex, dataField, value); this.dataGrid.instance.saveEditData(); } } @NgModule({ imports: [ // ... DxDataGridModule ], // ... })
Vue
<template> <DxDataGrid ... :ref="dataGridRefKey"> </DxDataGrid> </template> <script> import 'devextreme/dist/css/dx.common.css'; import 'devextreme/dist/css/dx.light.css'; import { DxDataGrid } from 'devextreme-vue/data-grid'; const dataGridRefKey = 'my-data-grid'; export default { components: { DxDataGrid }, data() { return { dataGridRefKey }; }, methods: { updateCell(rowIndex, dataField, value) { this.dataGrid.cellValue(rowIndex, dataField, value); this.dataGrid.saveEditData(); } }, computed: { dataGrid: function() { return this.$refs[dataGridRefKey].instance; } } } </script>
React
import React, { useRef } from 'react'; import 'devextreme/dist/css/dx.light.css'; import DataGrid from 'devextreme-react/data-grid'; export default function App() { const dataGrid = useRef(null); const updateCell = (rowIndex, dataField, value) => { dataGrid.current.instance.cellValue(rowIndex, dataField, value); dataGrid.current.instance.saveEditData(); }; return ( <DataGrid ... ref={dataGrid}> </DataGrid> ); }
See Also
cellValue(rowIndex, visibleColumnIndex)
The index of the row to which the cell belongs. Refer to Column and Row Indexes for more information.
cellValue(rowIndex, visibleColumnIndex, value)
The index of the row to which the cell belongs. Refer to Column and Row Indexes for more information.
Call saveEditData() after this method to save the changes:
jQuery
var dataGrid = $("#dataGridContainer").dxDataGrid("instance"); dataGrid.cellValue(0, 1, "newValue"); dataGrid.saveEditData();
Angular
import { ..., ViewChild } from "@angular/core"; import { DxDataGridModule, DxDataGridComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxDataGridComponent, { static: false }) dataGrid: DxDataGridComponent; // Prior to Angular 8 // @ViewChild(DxDataGridComponent) dataGrid: DxDataGridComponent; updateCell(rowIndex, columnIndex, value) { this.dataGrid.instance.cellValue(rowIndex, columnIndex, value); this.dataGrid.instance.saveEditData(); } } @NgModule({ imports: [ // ... DxDataGridModule ], // ... })
Vue
<template> <DxDataGrid ... :ref="dataGridRefKey"> </DxDataGrid> </template> <script> import 'devextreme/dist/css/dx.common.css'; import 'devextreme/dist/css/dx.light.css'; import { DxDataGrid } from 'devextreme-vue/data-grid'; const dataGridRefKey = 'my-data-grid'; export default { components: { DxDataGrid }, data() { return { dataGridRefKey }; }, methods: { updateCell(rowIndex, columnIndex, value) { this.dataGrid.cellValue(rowIndex, columnIndex, value); this.dataGrid.saveEditData(); } }, computed: { dataGrid: function() { return this.$refs[dataGridRefKey].instance; } } } </script>
React
import React, { useRef } from 'react'; import 'devextreme/dist/css/dx.light.css'; import DataGrid from 'devextreme-react/data-grid'; export default function App() { const dataGrid = useRef(null); const updateCell = (rowIndex, columnIndex, value) => { dataGrid.current.instance.cellValue(rowIndex, columnIndex, value); dataGrid.current.instance.saveEditData(); }; return ( <DataGrid ... ref={dataGrid}> </DataGrid> ); }
See Also
clearFilter(filterName)
The method's parameter specifies what type of filter should be cleared. This parameter can have one of the following values:
- "row"
Clears the filter row. - "header"
Clears the header filter. - "filterValue"
Clears the filter builder and the synchronized filtering UI elements. - "search"
Clears the search panel. - "dataSource"
Clears the data source filter defined in the configuration or applied by the filter(filterExpr) method.
See Also
closeEditCell()
Switches the cell being edited back to the normal state. Takes effect only if editing.mode is batch or cell and showEditorAlways is false.
See Also
collapseAll(groupIndex)
See Also
collapseRow(key)
A Promise that is resolved after the row is collapsed. It is a native Promise or a jQuery.Promise when you use jQuery.
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.
See Also
columnOption(id)
This method gets the properties of the first column found by either of the below:
Name
The unique name of the column.Column Index
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.Service String
A string that matches the following format: "optionName:value", where optionName is one of the column properties. For example, the following string corresponds to the command column:"type:buttons"
.
See Also
columnOption(id, optionName)
The column's index, data field, caption, type, or unique name. Refer to columnOption(id) for details.
columnOption(id, optionName, optionValue)
The column's index, data field, caption, type, or unique name. Refer to columnOption(id) for details.
columnOption(id, options)
The column's index, data field, caption, type, or unique name. Refer to columnOption(id) for details.
defaultOptions(rule)
defaultOptions is a static method that the UI component class supports. The following code demonstrates how to specify default properties for all instances of the DataGrid UI component in an application executed on the desktop.
jQuery
DevExpress.ui.dxDataGrid.defaultOptions({ device: { deviceType: "desktop" }, options: { // Here go the DataGrid properties } });
Angular
import DataGrid, { Properties } from "devextreme/ui/data_grid"; // ... export class AppComponent { constructor () { DataGrid.defaultOptions<Properties>({ device: { deviceType: "desktop" }, options: { // Here go the DataGrid properties } }); } }
Vue
<template> <div> <DxDataGrid id="dataGrid1" /> <DxDataGrid id="dataGrid2" /> </div> </template> <script> import DxDataGrid from "devextreme-vue/data-grid"; import DataGrid from "devextreme/ui/data_grid"; DataGrid.defaultOptions({ device: { deviceType: "desktop" }, options: { // Here go the DataGrid properties } }); export default { components: { DxDataGrid } } </script>
React
import dxDataGrid from "devextreme/ui/data_grid"; import DataGrid from "devextreme-react/data-grid"; dxDataGrid.defaultOptions({ device: { deviceType: "desktop" }, options: { // Here go the DataGrid properties } }); export default function App() { return ( <div> <DataGrid id="dataGrid1" /> <DataGrid id="dataGrid2" /> </div> ) }
deleteColumn(id)
This method removes the first column found by either of the below:
Name
The unique name of the column.Column Index
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.
See Also
deleteRow(rowIndex)
The row's index. Refer to Column and Row Indexes for more information.
See Also
deselectAll()
A Promise that is resolved after the selection is cleared. It is a native Promise or a jQuery.Promise when you use jQuery.
Depending on the value of the selectAllMode property, this method clears selection of all rows on all pages or on the currently rendered pages only. The selection is cleared of only those rows that meet filtering conditions if a filter is applied. To clear selection regardless of the selectAllMode property's value or applied filters, call the clearSelection() method.
See Also
deselectRows(keys)
Array<any>
A Promise that is resolved after selection is cleared. It is a native Promise or a jQuery.Promise when you use jQuery.
See Also
dispose()
jQuery
After calling this method, remove the DOM element associated with the UI component:
$("#myDataGrid").dxDataGrid("dispose"); $("#myDataGrid").remove();
Angular
Use conditional rendering instead of this method:
<dx-data-grid ... *ngIf="condition"> </dx-data-grid>
Vue
Use conditional rendering instead of this method:
<template> <DxDataGrid ... v-if="condition"> </DxDataGrid> </template> <script> import DxDataGrid from 'devextreme-vue/data-grid'; export default { components: { DxDataGrid } } </script>
React
Use conditional rendering instead of this method:
import React from 'react'; import DataGrid from 'devextreme-react/data-grid'; function DxDataGrid(props) { if (!props.shouldRender) { return null; } return ( <DataGrid ... > </DataGrid> ); } class App extends React.Component { render() { return ( <DxDataGrid shouldRender="condition" /> ); } } export default App;
editCell(rowIndex, dataField)
Switches a cell with a specific row index and a data field to the editing state. Takes effect only if the editing mode is "batch" or "cell".
The index of the row to which the cell belongs. Refer to Column and Row Indexes for more information.
editCell(rowIndex, visibleColumnIndex)
Switches a cell with specific row and column indexes to the editing state. Takes effect only if the editing mode is "batch" or "cell".
The index of the row to which the cell belongs. Refer to Column and Row Indexes for more information.
editRow(rowIndex)
Switches a row with a specific index to the editing state. Takes effect only if the editing mode is "row", "popup" or "form".
The row's index. Refer to Column and Row Indexes for more information.
See Also
endCustomLoading()
Hides the load panel.
Normally, the UI component hides the load panel automatically once data 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.
See Also
endUpdate()
Refreshes the UI component after a call of the beginUpdate() method.
Main article: beginUpdate()
See Also
expandAdaptiveDetailRow(key)
To access a data row by its key, you should specify the field that provides keys in the data source. If no key was specified, the whole data object is considered the key.
See Also
expandAll(groupIndex)
See Also
expandRow(key)
A Promise that is resolved after the row is expanded. It is a native Promise or a jQuery.Promise when you use jQuery.
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.
A group row can also be expanded when you navigate to a data row within it. See navigateToRow(key) for more information.
See Also
exportToExcel(selectionOnly)
Use the exportDataGrid(options) method instead.
filter()
Gets a filter expression applied to the UI component's data source using the filter(filterExpr) method and the DataSource's filter property.
See Also
filter(filterExpr)
Applies a filter to the dataSource.
The filter passed to this method is not reflected in any of the filtering UI elements and is applied before these elements' filters. To change UI filters in code, use the following properties instead:
Filtering UI Element | Property |
---|---|
Filter Row | columns[].filterValue and columns[].selectedFilterOperation |
Header Filter | columns[].filterValues and columns[].filterType |
Intergrated Filter Builder | filterValue |
Search Panel | searchPanel.text |
To clear all filters applied in code and the UI, call the clearFilter() method.
See Also
getCellElement(rowIndex, dataField)
The index of the row to which the cell belongs. Refer to Column and Row Indexes for more information.
The data field, caption, or unique name of the column to which the cell belongs.
The cell's container. It is an HTML Element or a jQuery Element when you use jQuery.
If the specified row or data field does not exist, the method returns undefined.
getCellElement(rowIndex, visibleColumnIndex)
The index of the row to which the cell belongs. Refer to Column and Row Indexes for more information.
The cell's container. It is an HTML Element or a jQuery Element when you use jQuery.
If the specified row or column does not exist, the method returns undefined.
getCombinedFilter()
Use this method to get the total filter. This filter combines filters applied using filtering UI elements and the filter(filterExpr) method. Note that the total filter contains getters. To get the total filter containing data fields, call the getCombinedFilter(returnDataField) method.
See Also
getCombinedFilter(returnDataField)
Use this method to get the total filter. This filter combines filters applied using filtering UI elements and the filter(filterExpr) method.
See Also
getDataSource()
Gets the DataSource instance.
See Also
getInstance(element)
getInstance is a static method that the UI component class supports. The following code demonstrates how to get the DataGrid instance found in an element with the myDataGrid
ID:
// Modular approach import DataGrid from "devextreme/ui/data_grid"; ... let element = document.getElementById("myDataGrid"); let instance = DataGrid.getInstance(element) as DataGrid; // Non-modular approach let element = document.getElementById("myDataGrid"); let instance = DevExpress.ui.dxDataGrid.getInstance(element);
See Also
getKeyByRowIndex(rowIndex)
The row's visible index. Refer to Column and Row Indexes for more information.
See Also
getRowElement(rowIndex)
The row's visible index. Refer to Column and Row Indexes for more information.
Note that if the UI component has fixed columns, the method returns an array of two separate elements: with unfixed and with fixed columns.
See Also
getRowIndexByKey(key)
The row's index; -1 if nothing found. Refer to Column and Row Indexes for more information.
See Also
getScrollable()
For information on API members of the scrollable part, refer to the ScrollView section. The list below shows ScrollView members that are unavailable for this method.
Properties:
- pullingDownText
- pulledDownText
- refreshingText
- reachBottomText
- onPullDown
- onReachBottom
Methods:
- release(preventScrollBottom)
- refresh()
See Also
getSelectedRowKeys()
The whole data object is considered a key if the field providing keys is not specified in the data source. In this case, this method returns data objects, that is, operates like the getSelectedRowsData() method.
Note that when selection is deferred, the method returns a Promise (a native Promise or a jQuery.Promise when you use jQuery) that should be resolved with an array of keys.
See Also
getSelectedRowsData()
The selected rows' data objects.
The objects are not processed by the DataSource and have the same order in which the rows were selected.
When selection is deferred, the method returns a Promise (a native Promise or a jQuery.Promise when you use jQuery) that is resolved with the selected rows' data objects.
jQuery
var dataGrid = $("#dataGridContainer").dxDataGrid("instance"); var selectedRowsData = dataGrid.getSelectedRowsData(); // ===== or when deferred selection is used ===== dataGrid.getSelectedRowsData().then(function(selectedRowsData) { // Your code goes here });
Angular
import { Component, ViewChild } from '@angular/core'; import { DxDataGridComponent } from 'devextreme-angular'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { @ViewChild('dataGridRef', { static: false }) dataGrid: DxDataGridComponent; // Prior to Angular 8 // @ViewChild('dataGridRef') dataGrid: DxDataGridComponent; selectedRowsData = []; getSelectedData() { this.selectedRowsData = this.dataGrid.instance.getSelectedRowsData(); // ===== or when deferred selection is used ===== this.dataGrid.instance.getSelectedRowsData().then((selectedRowsData) => { // Your code goes here }); } }
<dx-data-grid ... #dataGridRef ></dx-data-grid>
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxDataGridModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxDataGridModule ], providers: [ ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
<template> <DxDataGrid ... :ref="dataGridRef"> </DxDataGrid> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxDataGrid from 'devextreme-vue/data-grid'; const dataGridRef = 'dataGrid'; export default { components: { DxDataGrid }, data() { return { dataGridRef, selectedRowsData: [] } }, computed: { dataGrid: function() { return this.$refs[dataGridRef].instance; } }, methods: { getSelectedData() { this.selectedRowsData = this.dataGrid.getSelectedRowsData(); // ===== or when deferred selection is used ===== this.dataGrid.getSelectedRowsData().then((selectedRowsData) => { // Your code goes here }); } } } </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import DataGrid from 'devextreme-react/data-grid'; class App extends React.Component { constructor(props) { super(props); this.dataGridRef = React.createRef(); this.selectedRowsData = []; this.getSelectedData = () => { this.selectedRowsData = this.dataGrid.getSelectedRowsData(); // ===== or when deferred selection is used ===== this.dataGrid.getSelectedRowsData().then((selectedRowsData) => { // Your code goes here }); } } get dataGrid() { return this.dataGridRef.current.instance; } render() { return ( <DataGrid ... ref={this.dataGridRef}> </DataGrid> ); } } export default App;
ASP.NET MVC Controls
@(Html.DevExtreme().DataGrid() .ID("dataGrid") @* ... *@ ) <script type="text/javascript"> function getSelectedData() { var dataGrid = $("#dataGrid").dxDataGrid("instance"); var selectedRowsData = dataGrid.getSelectedRowsData(); // ... // ===== or when deferred selection is used ===== dataGrid.getSelectedRowsData().then(function(selectedRowsData) { // Your code goes here }); } </script>
See Also
getVisibleColumnIndex(id)
The column's index, data field, caption, type, or unique name. Refer to columnOption(id) for details.
getVisibleColumns(headerLevel)
Gets all visible columns at a specific hierarchical level of column headers. Use it to access banded columns.
See Also
isAdaptiveDetailRowExpanded(key)
To access a data row by its key, specify the field that provides keys in the data source. If no key was specified, the whole data object is considered the key.
See Also
isRowExpanded(key)
To check whether a group row is expanded, call this method with an array, in which each member is a grouping value. To check if a master row is expanded, pass its key to this method.
See Also
isRowSelected(data)
Checks whether a row found using its data object is selected. Takes effect only if selection.deferred is true.
isRowSelected(key)
Checks whether a row with a specific key is selected. Takes effect only if selection.deferred is false.
navigateToRow(key)
A Promise that is resolved after the grid is navigated to the specified row. It is a native Promise or a jQuery.Promise when you use jQuery.
This method performs the following actions:
- Switches the UI component to the data page that contains the specified row.
- Expands groups in which the row is nested (if rows are grouped and the groups are collapsed).
- Scrolls the UI component to display the row (if the row is outside the viewport).
The following requirements apply when you use this method:
The UI component's keyExpr or the store's key property should be specified.
Rows should be initially sorted by keys. You can sort them on the server or use a column's sortOrder or the DataSource's sort property to sort the rows on the client.
Scrolling mode should not be "infinite".
See Also
on(eventName, eventHandler)
Use this method to subscribe to one of the events listed in the Events section.
See Also
on(events)
Use this method to subscribe to several events with one method call. Available events are listed in the Events section.
See Also
pageCount()
See Also
pageIndex()
When the scrolling mode is "virtual" or "infinite", this method returns the index of the page whose row is shown first in the UI component.
See Also
pageIndex(newIndex)
A Promise that is resolved after the page is shown. It is a native Promise or a jQuery.Promise when you use jQuery.
refresh()
A Promise that is resolved after data is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.
The UI component cannot track changes a third party makes in the data source. To update data in the UI component in this case, call the refresh() method. Data sources of lookup columns are updated with the main data source.
The following code shows how to call this method:
jQuery
var dataGrid = $("#dataGridContainer").dxDataGrid("instance"); dataGrid.refresh() .done(function() { // ... }) .fail(function(error) { // ... });
Angular
<dx-data-grid #dataGridVar ... > <!-- ... --> </dx-data-grid>
import { Component, ViewChild } from '@angular/core'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { @ViewChild('dataGridVar', { static: false }) dataGrid: DxDataGridComponent; // Prior to Angular 8 // @ViewChild('dataGridVar') dataGrid: DxDataGridComponent; refreshDataGrid() { this.dataGrid.instance.refresh() .then(function() { // ... }) .catch(function(error) { // ... }); } }
Vue
<template> <DxDataGrid ... :ref="dataGridRefKey"> <!-- ... --> </DxDataGrid> </template> <script> import 'devextreme/dist/css/dx.light.css'; import { DxDataGrid, /* ... */ } from 'devextreme-vue/data-grid'; const dataGridRefKey = 'my-data-grid'; export default { components: { DxDataGrid, // ... }, data() { return { dataGridRefKey }; }, computed: { dataGrid: function() { return this.$refs[dataGridRefKey].instance; } }, methods: { refreshDataGrid() { this.dataGrid.refresh() .then(function() { // ... }) .catch(function(error) { // ... }); } } }; </script>
React
import React from 'react'; import 'devextreme/dist/css/dx.light.css'; import { DataGrid, /* ... */ } from 'devextreme-react/data-grid'; class App extends React.Component { render() { return ( <DataGrid ... ref={ref => this.dataGrid = ref}> {/* ... */} </DataGrid> ); } refreshDataGrid() { this.dataGrid.instance.refresh() .then(function() { // ... }) .catch(function(error) { // ... }); } } export default App;
ASP.NET MVC Controls
@(Html.DevExtreme().DataGrid() .ID("dataGridContainer") // ... ) <script type="text/javascript"> function refreshDataGrid() { var dataGrid = $("#dataGridContainer").dxDataGrid("instance"); dataGrid.refresh() .done(function() { // ... }) .fail(function(error) { // ... }); } </script>
See Also
refresh(changesOnly)
A Promise that is resolved after data is loaded. It is a native Promise or a jQuery.Promise when you use jQuery.
repaintRows(rowIndexes)
Row indexes. Refer to Column and Row Indexes for more information.
This method updates the row objects and their visual representation.
See Also
saveEditData()
A Promise that is resolved after changes are saved in the data source. It is a native Promise or a jQuery.Promise when you use jQuery.
See Also
searchByText(text)
Seeks a search string in the columns whose allowSearch property is true.
See Also
selectAll()
A Promise that is resolved after all rows are selected. It is a native Promise or a jQuery.Promise when you use jQuery.
Depending on the value of the selectAllMode property, this method selects all rows on all pages or on the currently rendered pages only. If a filter is applied, this method selects only those rows that meet the filtering conditions.
See Also
selectRows(keys, preserve)
A Promise that is resolved after the rows are selected. It is a native Promise or a jQuery.Promise when you use jQuery.
By default, this method call clears selection of previously selected rows. To keep these rows selected, call this method with true as the second argument.
widgetInstance.selectRows([5, 10, 12], true);
If you specify DataGrid's key as composite (for example, key: ['id', 'name']
), you need to call this method as follows:
widgetInstance.selectRows([ { id: 5, name: 'Alex' }, { id: 10: name: 'Bob' } ], true);
See Also
selectRowsByIndexes(indexes)
A Promise that is resolved after the rows are selected. It is a native Promise or a jQuery.Promise when you use jQuery.
This method has the following specifics:
- This method call clears selection of all previously selected rows.
- When calculating row indexes, the UI component counts data and group rows. Nevertheless, only data rows can be selected.
- If the pager is used, selection is cleared once a user moves to a different page. To preserve it, call this method within the onContentReady handler.
See Also
state()
The following example shows how to save the UI component state in the local storage and load it from there:
jQuery
$(function () { const dataGrid = $("#dataGridContainer").dxDataGrid({ // ... }).dxDataGrid("instance"); $("#save").dxButton({ text: "Save State", onClick: function() { const state = dataGrid.state(); // Saves the state in the local storage localStorage.setItem("dataGridState", JSON.stringify(state)); } }); $("#load").dxButton({ text: "Load State", onClick: function() { const state = JSON.parse(localStorage.getItem("dataGridState")); dataGrid.state(state); } }); });
Angular
import { Component, ViewChild } from "@angular/core"; import { DxDataGridModule, DxButtonModule, DxDataGridComponent } from "devextreme-angular"; // ... export class AppComponent { @ViewChild(DxDataGridComponent, { static: false }) dataGrid: DxDataGridComponent // Prior to Angular 8 // @ViewChild(DxDataGridComponent) dataGrid: DxDataGridComponent saveState() { const state = this.dataGrid.instance.state(); // Saves the state in the local storage localStorage.setItem("dataGridState", JSON.stringify(state)); } loadState() { const state = JSON.parse(localStorage.getItem("dataGridState")); this.dataGrid.instance.state(state); } } @NgModule({ imports: [ DxDataGridModule, DxButtonModule, // ... ], // ... })
<dx-data-grid ...> </dx-data-grid> <dx-button text="Save State" (onClick)="saveState()"> </dx-button> <dx-button text="Load State" (onClick)="loadState()"> </dx-button>
Vue
<template> <DxDataGrid ... :ref="dataGridRefKey"> </DxDataGrid> <DxButton text="Save State" @click="saveState" /> <DxButton text="Load State" @click="loadState" /> </template> <script> import 'devextreme/dist/css/dx.light.css'; import DxDataGrid, { // ... } from 'devextreme-vue/data-grid'; import DxButton from 'devextreme-vue/button'; const dataGridRefKey = "my-data-grid"; export default { components: { DxDataGrid, // ... DxButton }, data() { return { dataGridRefKey } }, methods: { saveState() { const state = this.dataGrid.state(); // Saves the state in the local storage localStorage.setItem("dataGridState", JSON.stringify(state)); }, loadState() { const state = JSON.parse(localStorage.getItem("dataGridState")); this.dataGrid.state(state); } }, computed: { dataGrid: function() { return this.$refs[dataGridRefKey].instance; } } } </script>
React
import React, { useRef } from 'react'; import 'devextreme/dist/css/dx.light.css'; import DataGrid, { // ... } from 'devextreme-react/data-grid'; import Button from 'devextreme-react/button'; export default function App() { const dataGrid = useRef(null); const saveState = () => { const state = dataGrid.current.instance.state(); // Saves the state in the local storage localStorage.setItem("dataGridState", JSON.stringify(state)); }; const loadState = () => { const state = JSON.parse(localStorage.getItem("dataGridState")); dataGrid.current.instance.state(state); }; return ( <React.Fragment> <DataGrid ... ref={dataGrid}> </DataGrid> <Button text="Save State" onClick={saveState} /> <Button text="Load State" onClick={loadState} /> </React.Fragment> ); }
See Also
state(state)
After the state is set, the DataGrid reloads data to apply sorting, filtering, and other data processing settings.
Refer to the state() method description for an example of how to work with the UI component state.
See Also
totalCount()
Please review the following notes:
If any filter is applied, totalCount() returns the count of records after filtering.
If paging is disabled in the DataGrid (paging.enabled is false) or in the underlying DataSource (paginate is false), totalCount() returns -1. To get the total record count in this case, you can use the following code:
jQuery
index.jsconst dataGrid = $("#dataGridContainer").dxDataGrid("instance"); const dataSource = dataGrid.getDataSource(); const recordCount = dataSource.items().length;
Angular
app.component.tsapp.component.htmlapp.module.tsimport { Component, ViewChild } from '@angular/core'; import { DxDataGridComponent } from 'devextreme-angular'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { @ViewChild('dataGridRef', { static: false }) dataGrid: DxDataGridComponent; // Prior to Angular 8 // @ViewChild('dataGridRef') dataGrid: DxDataGridComponent; getRecordCount() { const dataSource = this.dataGrid.instance.getDataSource(); return dataSource.items().length; } }
<dx-data-grid ... #dataGridRef ></dx-data-grid>
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { DxDataGridModule } from 'devextreme-angular'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, DxDataGridModule ], providers: [ ], bootstrap: [AppComponent] }) export class AppModule { }
Vue
App.vue<template> <DxDataGrid ... :ref="dataGridRef"> </DxDataGrid> </template> <script> import 'devextreme/dist/css/dx.common.css'; import 'devextreme/dist/css/dx.light.css'; import DxDataGrid from 'devextreme-vue/data-grid'; const dataGridRef = 'dataGrid'; export default { components: { DxDataGrid }, data() { return { dataGridRef } }, computed: { dataGrid: function() { return this.$refs[dataGridRef].instance; } }, methods: { getRecordCount() { const dataSource = this.dataGrid.getDataSource(); return dataSource.items().length; } } } </script>
React
App.jsimport React, { useRef, useCallback } from 'react'; import 'devextreme/dist/css/dx.light.css'; import DataGrid from 'devextreme-react/data-grid'; export default function App() { const dataGrid = useRef(null); const getRecordCount = useCallback(() => { const dataSource = dataGrid.current.instance.getDataSource(); return dataSource.items().length; }, []); return ( <DataGrid ref={dataGrid}> {/* ... */} </DataGrid> ); }
See Also
undeleteRow(rowIndex)
Recovers a row deleted in batch editing mode.
The row's index. Refer to Column and Row Indexes for more information.
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.