Reputation: 591
I have a datatable that are filled by results from mysql. The number of rows depends on the number of results from the mysql. I need to the DataTable fill by rows all empty screen space, whatever of the number of mysql results. In other words: the top of DataTable rows will be filled, and the bottom ones will be empty if number of results is less than the rows number. How it works now:
SingleChildScrollView _dataColumn() {
return SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
child: CustomDataTable(
columns: [
DataColumn(
label: Text('Teachers'),
),
],
rows: _filterEmployees
.map(
(employee) => DataRow(cells: [
DataCell(
Text(
employee.teachName,
),
onTap: () {
...
});
},
),
]),
)
.toList(),
),
),
);
}
Upvotes: 1
Views: 406
Reputation: 3713
Why not just use List Generate for a fixed number of iterations and mapping over the number in the employees.
SingleChildScrollView _dataColumn() {
return SingleChildScrollView(
scrollDirection: Axis.vertical,
child: SingleChildScrollView(
child: CustomDataTable(
columns: [
DataColumn(
label: Text('Teachers'),
),
],
rows:
List<int>.generate(10, (i) => i).map((num) {
if (num < _filterEmployees.length) {
return _filterEmployees[num];
}
//Default Employee object
return Employee();
}).map((employee) => DataRow(cells: [
DataCell(
Text(
employee.teachName,
),
onTap: () {
...
});
},
),
]),
)
.toList(),
),
),
);
}
Now your Datatable
will always consist of 10 entries, first entries will be filled but later on there will be empty entries.
Upvotes: 1