question
Hi, I have a few questions as below,
- How to refresh the grid when new rows are coming in from another screen
- How to display the total number of records or adding up the total for numeric columns on footer (Tried coding as below not working)
createFooter: (stateManager) {// default 40 return _Footer(stateManager: stateManager); },
class _Footer extends StatefulWidget { const _Footer({ required this.stateManager, Key? key, }) : super(key: key);
final PlutoGridStateManager stateManager;
@override State<_Footer> createState() => _FooterState(); }
class _FooterState extends State<_Footer> { int sum = 0;
late final String Function(dynamic value) format;
@override void initState() { super.initState();
/// If the value is changed by registering a listener, call setState to update the value.
widget.stateManager.addListener(listener);
/// This is to use the format of the existing number column.
/// You can use the Intl package to override this.
format = widget.stateManager.columns
.firstWhere(
(element) => element.type is PlutoColumnTypeNumber,
)
.type
.number!
.applyFormat;
}
@override void dispose() { widget.stateManager.removeListener(listener);
sum = calculateSum();
super.dispose();
}
void listener() { int _sum = calculateSum();
if (_sum != sum) {
setState(() {
sum = _sum;
});
}
}
int calculateSum() { final int length = widget.stateManager.refRows.length;
int _sum = 0;
for (int i = 0; i < length; i += 1) {
final row = widget.stateManager.refRows[i];
_sum += (row.cells['number']!.value as int);// + (row.cells['column3']!.value as int);
}
return _sum;
}
@override Widget build(BuildContext context) { return SizedBox( height: widget.stateManager.footerHeight, child: Center( child: Text('Total ${format(sum)}'), ), ); } }
Thanks in advance for the reply
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.