Hi~
If I want to have 20 DataGridRow,
1~10 DataGridRow have data , 11~20
DataGridRow is empty,
or
1~8 DataGridRow have data, 9~20 DataGridRow is empty,
or
1~12 DataGridRow have data, 13~20 DataGridRow is empty,
DataGridSoruce's List length is dynamic.
I want to make excel style
DataGrid.
I find other platform relative articles:
https://www.syncfusion.com/forums/166400/is-there-a-way-to-make-the-grid-show-rows-with-no-data
but still need help. How can I make it?
,
class EmployeeDataGridSource extends DataGridSource {
EmployeeDataGridSource(
{required List<Employee> employeeData, required int emptyRowsCount}) {
_dataGridRows = employeeData
.map<DataGridRow>((e) => DataGridRow(cells: [
DataGridCell<int>(columnName: 'id', value: e.id),
DataGridCell<String>(columnName: 'name', value: e.name),
DataGridCell<String>(
columnName: 'designation', value: e.designation),
DataGridCell<int>(columnName: 'salary', value: e.salary),
]))
.toList();
for (int i = 0; i < emptyRowsCount; i++) {
_dataGridRows.add(const DataGridRow(cells: [
DataGridCell(columnName: 'id', value: null),
DataGridCell(columnName: 'name', value: null),
DataGridCell(columnName: 'designation', value: null),
DataGridCell(columnName: 'salary', value: null),
]));
}
}
List<DataGridRow> _dataGridRows = [];
@override
List<DataGridRow> get rows => _dataGridRows;
@override
DataGridRowAdapter buildRow(DataGridRow row) {
return DataGridRowAdapter(
cells: row.getCells().map<Widget>((e) {
return Container(
alignment: Alignment.center,
padding: const EdgeInsets.all(8.0),
child: Text(e.value?.toString() ?? ''),
);
}).toList());
}
} |
Hi~
Sangeetha,
Thanks for the reply, very useful!
Have a nice weekend.