Articles in this section
Category / Section

How to limit custom colors to cells in Flutter DataTable?

2 mins read

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());
  }

View the GitHub sample here.

Conclusion

I hope you enjoyed learning about how to limit custom colors to cells in Flutter DataTable.

You can refer to our Flutter DataTable feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Flutter DataTable example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied