Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to limit custom colors to cells in the selected row in Flutter DataTable (SfDataGrid)?

In this article, we will show you how to limit custom colors to cells in the selected row in Flutter DataTable.

Initialize the SfDataGrid widget with all the necessary properties. To limit the custom color to cells in the selected row, the buildRow method is called whenever a selection is made. You should verify if the row is part of the selected row collection using DataGridController.SelectedRows.

 @override
  DataGridRowAdapter buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map<Widget>((e) {
      Color? getColor() {
        if (!controller.selectedRows.contains(row)) {
          if (e.columnName == 'designation') {
            if (e.value == 'Developer') {
              return Colors.tealAccent;
            } else if (e.value == 'Manager') {
              return Colors.blue[200]!;
            }
          }
        }
        return null;
      }

      return Container(
        color: getColor(),
        alignment: Alignment.center,
        padding: const EdgeInsets.all(8.0),
        child: Text(e.value.toString()),
      );
    }).toList());
  }

You can download this example on GitHub.

About

How to limit custom colors to cells in the selected row in Flutter DataTable

Topics

Resources

Stars

0 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages