Hi,
I'm using loadmore widget in sfdatagrid. Please help me to get the current count of rows that is displayed and total count of rows. I m getting xml data to the grid and the data is dynamic. I tried creating a list and getting the current count from addmorerows function (to implement load more feature) but it is not working.
Hi Sarath Chandran,
Regarding: To get the current count of rows that is displayed.
Based on the provided details, we suspect that you need to get the rows count which is currently displayed in the view. Currently, the DataGrid doesn’t have support to get the rows currently in the view. We have already considered your request as a feature . This feature will be implemented in our 2023 Volume 4 release, which is expected to be rolled out at the end of December 2023. We will let you know when this feature is implemented. We appreciate your patience and understanding in the meantime.
You can also communicate with us regarding the open features any time using our Feature Report page.
Feedback link: https://www.syncfusion.com/feedback/44216/support-to-get-the-visible-rows-in-the-view
Regarding: To get the total count of rows.
You can get the total row count by finding the length of the DataGridSource.rows property. Please check the following code snippet for more information.
|
List<Employee> _employees = <Employee>[]; late EmployeeDataSource _employeeDataSource;
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Syncfusion Flutter DataGrid')), body: Column( children: [ Padding( padding: const EdgeInsets.all(16.0), child: ElevatedButton( onPressed: () { // show pop up showDialog( context: context, builder: (context) { return AlertDialog( title: Text( 'Total Rows Count : ${_employeeDataSource.rows.length.toString()}'), actions: [ TextButton( onPressed: () { Navigator.pop(context); }, child: const Text('OK')) ], ); }); }, child: const Text('Total Rows Count'))), Expanded( child: SfDataGrid( source: _employeeDataSource, columnWidthMode: ColumnWidthMode.fill, columns: getColumns, footerHeight: 70, footer: const SizedBox.shrink(), loadMoreViewBuilder: (BuildContext context, LoadMoreRows loadMoreRows) { Future<String> loadRows() async { await loadMoreRows(); return Future<String>.value('Completed'); }
return FutureBuilder<String>( initialData: 'loading', future: loadRows(), builder: (context, snapShot) { if (snapShot.data == 'loading') { return Container( height: 60.0, width: double.infinity, alignment: Alignment.center, child: const CircularProgressIndicator()); } else { return SizedBox.fromSize(size: Size.zero); } }, ); }, ), ), ], ), ); } |
Regards,
Tamilarasan
Thankyou Tamilarasan for letting me know about this.
Sarath Chandran,
We are glad to announce that our Essential Studio 2023 Volume 4 Main Release
V24.1.41 is rolled out and is available for download under the following link.
We are also glad to announce that support for "Retrieving the indices of visible rows and columns" has been incorporated into our 2023 Volume 4 Main Release. Please update the Syncfusion.Maui.DataGrid package to version 24.1.41.
Code Snippet for getting visible rows in the view:
|
DataGridController dataGridController = DataGridController(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('Syncfusion DataGrid Demo')), body: Column( children: [ Padding( padding: const EdgeInsets.symmetric(vertical: 10), child: ElevatedButton( onPressed: () { int? startRowIndex = dataGridController .getVisibleRowStartIndex(RowRegion.body); int? endRowIndex = dataGridController.getVisibleRowEndIndex(RowRegion.body); List<DataGridRow> visibleRows = []; if (startRowIndex != null && endRowIndex != null) { // Here, we are subtracting 1 because the row index starts from 0. // 1 is the header row count in this DataGrid. visibleRows = _employeeDataSource.effectiveRows .getRange(startRowIndex - 1, endRowIndex) .toList(); } for (var data in visibleRows) { print(data.getCells()[0].value); } }, child: const Text('Get Visible Rows')), ), Expanded( child: SfDataGrid( source: _employeeDataSource, controller: dataGridController, columns: getColumns, columnWidthMode: ColumnWidthMode.fill, ), ), ], ), ); } |
UG documentation: https://help.syncfusion.com/flutter/datagrid/scrolling#retrieve-the-indices-of-visible-rows-and-columns
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.
Regards,
Tamilarasan