Skip to content

SyncfusionExamples/How-to-get-cell-details-when-right-clicking-a-cell-in-Flutter-DataGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to get cell details when right-clicking a cell in Flutter DataGrid (SfDataGrid)?.

In this article, we will show you how to get cell details when right-clicking a cell in Flutter DataGrid.

Initialize the SfDataGrid widget with all required properties. Details about the right-clicked cell, such as rowColumnIndex, column, localPosition, and globalPosition, can be accessed through DataGridCellTapDetails, which is passed as a parameter in the onCellSecondaryTap callback. Furthermore, you can retrieve the value of the tapped cell from the effectiveRows collection using the RowColumnIndex.rowIndex property.

onCellSecondaryTap: (details) {
  showDialog(
    context: context,
    builder: (BuildContext context) {
      return AlertDialog(
        title: const Text('Tapped Cell Information'),
        content: SingleChildScrollView(
          child: ListBody(
            children: <Widget>[
              Text(
                'Column Index: ${details.rowColumnIndex.columnIndex}\n'
                'Row Index: ${details.rowColumnIndex.rowIndex}\n'
                'Column Name: ${details.column.columnName}',
              ),
              const SizedBox(height: 8),
              // Fetch details of the tapped cell value, excluding header cells.
              if (details.rowColumnIndex.rowIndex != 0)
                Text(
                  'Cell Value: ${employeeDataSource.effectiveRows[details.rowColumnIndex.rowIndex - 1].getCells()[details.rowColumnIndex.columnIndex].value}',
                ),
            ],
          ),
        ),
        actions: <Widget>[
          TextButton(
            child: const Text('OK'),
            onPressed: () {
              Navigator.of(context).pop();
            },
          ),
        ],
      );
    },
  );
},

You can download this example on GitHub.

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •