Skip to content

SyncfusionExamples/How-to-get-row-details-by-row-index-in-Flutter-DataGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to get row details by row index in Flutter DataGrid (SfDataGrid)?

In this article, we will show how to change scrollbar appearance in Flutter DataTable.

Initialize the SfDataGrid widget with its necessary properties. To retrieve row details in the DataGrid, use the controller property. First, create an instance of DataGridController and assign it to the DataGrid's controller property. Then, to obtain information about a specific row, call the getRowDetails method from the controller and pass the row index as a parameter.

@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          TextButton(
              onPressed: () {
                DataGridRowDetails? details =
                    _dataGridController.getRowDetails(4);
                if (details != null) {
                  print(details.rowType);
                  print(details.dataGridRow);
                  print(details.isSelected);
                }
              },
              child: Text('Get row details')),
          Expanded(
            child: SfDataGrid(
              source: employeeDataSource,
              controller: _dataGridController,
              columns: <GridColumn>[
                GridColumn(
                  columnName: 'id',
                  label: Container(
                    padding: EdgeInsets.all(16.0),
                    alignment: Alignment.center,
                    child: Text('ID'),
                  ),
                ),
                GridColumn(
                  columnName: 'name',
                  label: Container(
                    padding: EdgeInsets.all(8.0),
                    alignment: Alignment.center,
                    child: Text('Name'),
                  ),
                ),
                GridColumn(
                  columnName: 'designation',
                  label: Container(
                    padding: EdgeInsets.all(8.0),
                    alignment: Alignment.center,
                    child: Text('Designation'),
                  ),
                ),
                GridColumn(
                  columnName: 'salary',
                  label: Container(
                    padding: EdgeInsets.all(8.0),
                    alignment: Alignment.center,
                    child: Text('Salary'),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

You can download this example on GitHub.

About

This demo shows how to get row details by row index in Flutter DataGrid

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •