Edit Row with a button column, opening our customized dialog form, with the row data

Edit Row with a button column, opening our customized dialog form, with the row data.


1 Reply 1 reply marked as answer

TP Tamilarasan Paranthaman Syncfusion Team January 24, 2022 01:41 PM UTC

Hi Stefan Tsalapatis,  
  
DataGrid provides support to load the button widget in the data cells. You can load the button widget to the corresponding cell of DataGridRowAdaptor in the DataGridSource.buildRow method. Please check the following code snippet.  
 
@override 
  DataGridRowAdapter buildRow(DataGridRow row) { 
    return DataGridRowAdapter( 
        cells: row.getCells().map<Widget>((dataGridCell) { 
      return Container( 
        alignment: Alignment.center, 
        padding: const EdgeInsets.all(8.0), 
        child: dataGridCell.columnName == 'button' 
            ? LayoutBuilder( 
                builder: (BuildContext context, BoxConstraints constraints) { 
                return MaterialButton( 
                  onPressed: () { 
                    _updateTextFieldContext(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('Edit Details'), 
                        actions: _buildActionButtons(row, context), 
                        content: Scrollbar( 
                          child: SingleChildScrollView( 
                            scrollDirection: Axis.horizontal, 
                            child: Form( 
                              key: _formKey, 
                              child: _buildAlertDialogContent(), 
                            ), 
                          ), 
                        ), 
                      ), 
                    ); 
                  }, 
                  child: const Text('Begin Editing'), 
                  color: Colors.cyanAccent, 
                ); 
              }) 
            : Text(dataGridCell.value.toString()), 
      ); 
    }).toList()); 
  } 
 
 
As per your requirement, we have prepared a sample with a material button column, you can edit the row cell by clicking the respective buttons. 
 
 
We hope this helps. Please let us know if you need any further assistance. 
 
Regards, 
Tamilarasan  


Marked as answer
Loader.
Up arrow icon