rows not displaying reloaded data
Hi, I loaded the rows from a data source. First display is OK, but when I reloaded rows with changes from data source the displayed value is not refreshing the newly reloaded rows :
` GetX<TransaksiPinjamanAktifListStreamSvc>(builder: (_) { // stateManager.removeRows(stateManager.rows); initRowsFromDataSource(); // HERE the rows is reloaded , ex : rows= List<PlutoRow>.generate(...)
// stateManager.appendRows(rows);
return Expanded(
child: PlutoGrid(
columns: columns,
rows: rows,
onChanged: (PlutoGridOnChangedEvent event) {
print(event);
},
onLoaded: (PlutoGridOnLoadedEvent event) {
event.stateManager
.setSelectingMode(PlutoGridSelectingMode.row);
stateManager = event.stateManager;
},
),
);
}),`
How to force the grid to refresh data rows?
Hello,
This is the way i handle the refresh data of the rows :
SchedulerBinding.instance.addPostFrameCallback((_) {
ShowLoadingDialog(contextApp);
});
stateManager.removeRows(plutorows);
plutorows = List();
final bool dataLoaded = await _piecerechangeCon.refreshData();
if (dataLoaded) {
loadAllPlutoColumn();
loadAllPlutorows();
}
SchedulerBinding.instance.addPostFrameCallback((_) {
hideLoadingDialog(contextApp);
});
if(mounted)setState(() {
if(stateManager != null && plutorows!=null)
stateManager.appendRows(plutorows);
});
And when i load all my rows 2 things 👍
void loadAllPlutorows() async {
//stateManager.removeRows(plutorows);
plutorows = List();
for(int u =0 ; u <_allmydata.length ; u++)
{
Map<String, PlutoCell> Innercells= Map();
int i = 0;
Innercells.putIfAbsent(i.toString(), () => PlutoCell(value: _piecerechangeCon.data[u].Nom.toString()));
plutorows.add( new PlutoRow( cells : Innercells));
}
if(mounted)setState(() {
if(stateManager != null && plutorows!=null)
stateManager.appendRows(plutorows);
});
}
I'm trying to use PlutoGrid with GetX as well, and hit this problem. Whenever data is updated, grid shows old data. Is it a bug or something undocumented in how this grid works?
Documentation is lacking. And I don't have enough time. plutoGrid needs to add or delete rows through stateManager. Otherwise, simply call stateManager.notifyListeners() . stateManager can receive an instance from the onLoaded callback when creating plutoGird .
@divan did u solve your problem? i have the same problem
I'm trying to use PlutoGrid with GetX as well, and hit this problem. Whenever data is updated, grid shows old data. Is it a bug or something undocumented in how this grid works?
Same issue, also using GetX, I solve the problem by returning a new PlutoGrid widget after data update. Like this:
Widget _buildTable(RowData data) {
return PlutoGrid(
...
row: _buildPlutoRows(data), // Data comes from GetxController.
key: UniqueKey(), // Use unique key to tell flutter to refresh.
...
);
}
class TablePage() extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Obx(() => _buildTable(controller.rowData.value));
}
}
It's not elegant and may cost more, but I have no other solution.
@realth000 , can you indicate a little more detail of your solution, I try to do the same, without success.
@conium try the demo here https://github.com/realth000/demo_plutogrid_getx
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.
return PlutoGrid( ... row: _buildPlutoRows(data), // Data comes from GetxController. key: UniqueKey()
Thank you! It did work for me. All I had to add is key: UniqueKey() and PlutoGrid started refreshing.
@pragmaticway can you provide a detailed example of your implementation please?
A mix of the GetBuilder, UniqueKey and use of the Update() method on the controller did the job for me:
`class GridController extends GetxController { PlutoGridStateManager? stateManager; TextEditingController filterController = TextEditingController(); List<PlutoRow> plutoRows = <PlutoRow>[]; List<PlutoColumn> plutoColumns = <PlutoColumn>[];
@override void onInit() {
plutoColumns = [
PlutoColumn(
title: 'Column 1',
field: 'column1',
type: PlutoColumnType.text(),
),
PlutoColumn(
title: 'Column 2',
field: 'column2',
type: PlutoColumnType.text(),
),
// Add more columns as needed
];
plutoRows = [
PlutoRow(
cells: {
'column1': PlutoCell(value: 'Row 1 Column 1'),
'column2': PlutoCell(value: 'Row 1 Column 2'),
},
),
PlutoRow(
cells: {
'column1': PlutoCell(value: 'Row 2 Column 1'),
'column2': PlutoCell(value: 'Row 2 Column 2'),
},
), // Add more rows as needed
];
stateManager = PlutoGridStateManager(
columns: <PlutoColumn>[],
rows: <PlutoRow>[],
gridFocusNode: FocusNode(),
scroll: PlutoGridScrollController(),
);
super.onInit();
}
void filterRows(String value) { if (value.isEmpty) { //NIT stateManager!.resetFilter(); return; }
update();
}
void filter1stRow() { plutoRows = [ PlutoRow( cells: { 'column1': PlutoCell(value: 'Row 1 Column 1'), 'column2': PlutoCell(value: 'Row 1 Column 2'), }, ), ]; update(); }
void filter2ndRow() { plutoRows = [ PlutoRow( cells: { 'column1': PlutoCell(value: 'Row 2 Column 1'), 'column2': PlutoCell(value: 'Row 2 Column 2'), }, ), // Add more rows as needed ]; update(); }
}
class MyGridPage extends StatelessWidget { final GridController controller = Get.put(GridController());
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Pluto Grid with GetX'), ), body: Column( children: [ Padding( padding: const EdgeInsets.all(8.0), child: TextField( controller: controller.filterController, onChanged: (value) { controller.filterRows(value); }, decoration: InputDecoration( labelText: 'Filter Rows', hintText: 'Enter filter text...', prefixIcon: Icon(Icons.search), border: OutlineInputBorder(), ), ), ), Padding( padding: const EdgeInsets.all(8.0), child: ElevatedButton( child: const Text('Row 1'), onPressed: () { controller.filter1stRow(); }, ), ), Padding( padding: const EdgeInsets.all(8.0), child: ElevatedButton( child: const Text('Row 2'), onPressed: () { controller.filter2ndRow(); }, ), ), Expanded( child: GetBuilder<GridController>( builder: (_) => PlutoGrid( columns: controller.plutoColumns, // Accessing rows from the controller //rows: controller.stateManager!.rows, rows: controller.plutoRows, key: UniqueKey(), ), ), ), ], ), ); } }`