Articles in this section

How to Retrieve Additional Row Cell Details in Flutter DataGrid?

In this article, we will show you how to retrieve additional row details by expanding a cell in Flutter DataGrid.

Initialize the SfDataGrid widget with all the required properties. In the buildRow method, load the cell value along with the icon button, and call showDialog. The onPressed event of the IconButton in the buildRow method is where the dialog is triggered. This dialog displays the expanded details.

class EmployeeDataSource extends DataGridSource {

…..

 @override
  DataGridRowAdapter buildRow(DataGridRow row) {
    return DataGridRowAdapter(
        cells: row.getCells().map<Widget>((DataGridCell cell) {
      return Container(
        alignment: Alignment.center,
        child: cell.columnName == 'Name'
            ? Row(
                children: [
                  Expanded(
                    child: Container(
                      alignment: Alignment.centerLeft,
                      child: Text(
                        cell.value.toString(),
                      ),
                    ),
                  ),
                  SizedBox(
                    width: 40,
                    child: Builder(builder: (context) {
                      datagridRows.indexOf(row);
                      return IconButton(
                        hoverColor: Colors.transparent,
                        color: Colors.blue,
                        icon: const Icon(Icons.expand_more),
                        onPressed: () => _showDetailsDialog(context, row),
                      );
                    }),
                  )
                ],
              )
            : Container(
                padding: const EdgeInsets.symmetric(horizontal: 8.0),
                alignment:
                    cell.columnName == 'ID' || cell.columnName == 'Salary'
                        ? Alignment.centerRight
                        : Alignment.centerLeft,
                child: Text(
                  cell.value.toString(),
                ),
              ),
      );
    }).toList());
  }

  void _showDetailsDialog(BuildContext context, DataGridRow row) {
    int rowIndex = datagridRows.indexOf(row);
    showDialog<String>(
      context: context,
      builder: (BuildContext context) => AlertDialog(
        scrollable: true,
        titleTextStyle: const TextStyle(
          color: Colors.black,
          fontWeight: FontWeight.bold,
          fontSize: 16,
        ),
        title: const Text('Personal Details'),
        actions: [
          TextButton(
            onPressed: () => Navigator.pop(context),
            child: const Text('Close'),
          ),
        ],
        content: Padding(
          padding: const EdgeInsets.all(20.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text('Employee address: ${employees[rowIndex].address}'),
              const SizedBox(height: 10),
              Text('City: ${employees[rowIndex].city}'),
              const SizedBox(height: 10),
              Text('Country: ${employees[rowIndex].country}'),
            ],
          ),
        ),
      ),
    );
  }
}

View the GitHub sample here.

Conclusion
I hope you enjoyed learning how to retrieve additional row cell details in Flutter DataGrid.
You can refer to our Flutter DataGrid 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 Flatter DataGrid 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)
Access denied
Access denied