It is possible to put a button in the cell and receive the clicked object?

I've been trying to do this and I didn't find a way to make it work with sfDataGrid.

I just receive the cell index when i tap in the cell, but when i want to tap in the button, there is nothing to obtain data from there.


Attachment: code_11c25cdf.rar

3 Replies 1 reply marked as answer

TP Tamilarasan Paranthaman Syncfusion Team April 15, 2022 10:56 AM UTC

Hi DIEGO Martin FURIATI,


As per your requirement, you can get the tapped cell data from the buildRow method in the DataGridSource. We have prepared the sample for that. In this sample, you can get the tapped row data with a button click. We show the respective row detail in the AlertDialog with a button click. Please check the following sample and code snippet.


Code snippet:

  @override

  DataGridRowAdapter? buildRow(DataGridRow row) {

    return DataGridRowAdapter(

        cells: row.getCells().map<Widget>((dataGridCell) {

      return Container(

          alignment: Alignment.center,

          child: dataGridCell.columnName == 'button'

              ? LayoutBuilder(

                  builder: (BuildContext context, BoxConstraints constraints) {

                  return ElevatedButton(

                      onPressed: () {

                        showDialog(

                            context: context,

                            builder: (context) => AlertDialog(

                                content: SizedBox(

                                    height: 100,

                                    child: Column(

                                      mainAxisAlignment:

                                          MainAxisAlignment.spaceBetween,

                                      children: [

                                        Text(

                                            'Employee ID: ${row.getCells()[0].value.toString()}'),

                                        Text(

                                            'Employee Name: ${row.getCells()[1].value.toString()}'),

                                        Text(

                                            'Employee Designation: ${row.getCells()[2].value.toString()}'),

                                      ],

                                    ))));

                      },

                      child: Text(dataGridCell.value));

                })

              : Text(dataGridCell.value.toString()));

    }).toList());

  }



Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/sample1472739247


We hope this helps and please let us know if you need any further assistance.


Regards,

Tamilarasan


Marked as answer

DM DIEGO Martin FURIATI April 16, 2022 04:06 PM UTC

Thank you!



TP Tamilarasan Paranthaman Syncfusion Team April 18, 2022 08:56 AM UTC

Hi DIEGO Martin,


We are glad that the provided response meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out. 


Regards,

Tamilarasan


Loader.
Up arrow icon