DataGridSource class Null safety

A datasource for obtaining the row data for the SfDataGrid.

The following APIs are mandatory to process the data,

  • rows - The number of rows in a datagrid and row selection depends on the rows. So, set the collection required for datagrid in rows.
  • buildRow - The data needed for the cells is obtained from buildRow.

Call the notifyDataSourceListeners when performing CRUD in the underlying datasource.

DataGridSource objects are expected to be long-lived, not recreated with each build.

final List<Employee> _employees = <Employee>[];

class EmployeeDataSource extends DataGridSource {
  @override
  List<DataGridRow> get rows => _employees
      .map<DataGridRow>((dataRow) => DataGridRow(cells: [
            DataGridCell<int>(columnName: 'id', value: dataRow.id),
            DataGridCell<String>(columnName: 'name', value: dataRow.name),
            DataGridCell<String>(
                columnName: 'designation', value: dataRow.designation),
            DataGridCell<int>(columnName: 'salary', value: dataRow.salary),
          ]))
      .toList();

  @override
  DataGridRowAdapter? buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map<Widget>((dataCell) {
          return Text(dataCell.value.toString());
        }).toList());
  }
}
Inheritance
Mixed in types

Constructors

DataGridSource()

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
hasListeners bool
Whether any listeners are currently registered. [...]
@protected, read-only, inherited
rows List<DataGridRow>
The collection of rows to display in SfDataGrid. [...]
read-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
sortedColumns List<SortColumnDetails>
The collection of SortColumnDetails objects to sort the columns in SfDataGrid. [...]
read-only

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes. [...]
inherited
buildRow(DataGridRow row) DataGridRowAdapter?
Called to obtain the widget for each cell of the row. [...]
compare(DataGridRow? a, DataGridRow? b, SortColumnDetails sortColumn) int
Called when the sorting is applied for column. This method compares the two objects and returns the order either they are equal, or one is greater than or lesser than the other. [...]
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener and removeListener will throw after the object is disposed). [...]
@mustCallSuper, inherited
handleLoadMoreRows() Future<void>
Called when LoadMoreRows function is called from the SfDataGrid.loadMoreViewBuilder. [...]
handlePageChange(int oldPageIndex, int newPageIndex) Future<bool>
Called when the page is navigated. [...]
inherited
handleRefresh() Future<void>
Called when the swipe to refresh is performed in SfDataGrid. [...]
handleSort() Future<bool>
Called when the sorting is applied to a column. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
notifyDataSourceListeners({RowColumnIndex? rowColumnIndex}) → void
Calls all the datagrid source listeners. Call this method whenever the underlying data is added or removed. If the value of the specific cell is updated, call this method with RowColumnIndex argument where it refers the corresponding row and column index of the cell.
@protected, inherited
notifyListeners() → void
Call all the registered listeners. [...]
@protected, inherited
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes. [...]
inherited
shouldRecalculateColumnWidths() bool
Called whenever you call notifyListeners or notifyDataSourceListeners in the DataGridSource class. If you want to recalculate all columns width (may be when underlying data gets changed), return true. [...]
sort() → void
Call this method when you are adding the SortColumnDetails programmatically to the DataGridSource.sortedColumns. [...]
toString() String
A string representation of this object. [...]
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited
operator [](int index) DataGridRow
An indexer to retrieve the data from the underlying datasource. If the sorting is applied, the data will be retrieved from the sorted datasource.