pluto_grid icon indicating copy to clipboard operation
pluto_grid copied to clipboard

question

Open asenthilkumarr opened this issue 3 years ago • 1 comments

Hi, I have a few questions as below,

  1. How to refresh the grid when new rows are coming in from another screen
  2. 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

asenthilkumarr avatar Aug 22 '22 12:08 asenthilkumarr

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Sep 22 '22 11:09 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Oct 06 '22 11:10 github-actions[bot]