One way to modify a Flutter paginated datatable to eliminate blank rows is to add a custom data source that only includes rows with data. You can do this by creating a new list of data that excludes any rows with empty values.
Here's an example:
List<Map<String, dynamic>> _data = [
{'id': 1, 'name': 'John', 'age': 28},
{'id': 2, 'name': '', 'age': 30},
{'id': 3, 'name': 'Jane', 'age': null},
{'id': 4, 'name': 'Alice', 'age': 25},
{'id': 5, 'name': 'Bob', 'age': 35},
];
class CustomDataSource extends DataTableSource {
int _selectedRowCount = 0;
@override
DataRow getRow(int index) {
if (index >= _data.length) return null;
final row = _data[index];
return DataRow(
cells: [
DataCell(Text(row['id'].toString())),
DataCell(Text(row['name'] ?? '')),
DataCell(Text(row['age']?.toString() ?? '')),
],
);
}
@override
bool get isRowCountApproximate => false;
@override
int get rowCount => _data.length;
@override
int get selectedRowCount => _selectedRowCount;
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('DataTable Example')),
body: PaginatedDataTable(
header: Text('Custom Data Source'),
columns: [
DataColumn(label: Text('ID')),
DataColumn(label: Text('Name')),
DataColumn(label: Text('Age')),
],
source: CustomDataSource(),
),
);
}
}
In this example, the _data
list contains some rows with empty or null values. CustomDataSource
implements DataTableSource
and returns only the rows with non-empty values. getRow()
checks if the index is less than the length of the new data list and returns null
otherwise, so only the existing rows are included in the paginated table. All the other methods are implemented according to the DataTableSource
interface.
By using a custom data source like this, you can eliminate the blank or null rows from your paginated datatable.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-19 23:41:10 +0000
Seen: 18 times
Last updated: May 19 '23
How can one obtain live data from interactive broker through API?
What is the method to implement pagination for Firestore data in Flutter using ListView?
What is the reason for the submitted Django form's value being null in the database?
How can we create summary tables by using nested tibbles?
What is the process of moving information from one tab to another in Excel by transposing it?
What does "coxphw undefined columns selected" mean?
Is it not possible to change the data type of an array from 'O' to 'float64'?
How to perform a historical backfill from GA4 into BigQuery?
How can Redux be integrated with Ag-Grid's server-side row model in React?