DropDownButton inside a Cell not working

Hi

I need to add a DropDownButton in a Cell. I tried this example (https://www.syncfusion.com/forums/160492/add-dropdownbutton-as-gridwidgetcolumn-in-datagrid) but it is not working. It seems that it uses an old API.


Can anybody help me?


Thanks



1 Reply

TP Tamilarasan Paranthaman Syncfusion Team February 7, 2022 10:48 AM UTC

Hi Marcio, 
 As per the DataGrid new API structure, you can load the Dropdown button widget to the corresponding cell of DataGridRowAdaptor in the DataGridSource.buildRow method. We have documented all the breaking changes and its alternate APIs in below blog, 
 
Code Snippet: 
@override 
  DataGridRowAdapter? buildRow(DataGridRow row) { 
    return DataGridRowAdapter( 
        cells: row.getCells().map<Widget>((dataGridCell) { 
      return Container( 
          alignment: (dataGridCell.columnName == 'id' || 
                  dataGridCell.columnName == 'salary') 
              ? Alignment.centerRight 
              : Alignment.centerLeft, 
          padding: EdgeInsets.symmetric(horizontal: 16.0), 
          child: dataGridCell.columnName == 'designation' 
              ? DropdownButton<String>( 
                  value: dropdownvalue, 
                  items: items.map((String items) { 
                    return DropdownMenuItem( 
                      value: items, 
                      child: Text(items), 
                    ); 
                  }).toList(), 
                  onChanged: (String? newValue) { 
                    dropdownvalue = newValue!; 
                    _employees[2].designation = newValue; 
                    notifyListeners(); 
                  }) 
              : Text( 
                  dataGridCell.value.toString(), 
                  overflow: TextOverflow.ellipsis, 
                )); 
    }).toList()); 
  } 
 
Also, we have prepared the sample with the editing feature for that, you can tap the ship country or ship city column cells to select the value from the dropdown. Please check the following sample, 
  
We hope this helps. Please let us know if you need any further assistance. 
Regards, 
Tamilarasan

Loader.
Up arrow icon