pluto_grid icon indicating copy to clipboard operation
pluto_grid copied to clipboard

rows not displaying reloaded data

Open NoldyNayoan opened this issue 5 years ago • 4 comments

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?

NoldyNayoan avatar Apr 19 '21 04:04 NoldyNayoan

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);
      });
 
  }

jeansebastienZ avatar Apr 19 '21 07:04 jeansebastienZ

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?

divan avatar Jul 09 '21 18:07 divan

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 .

bosskmk avatar Jul 19 '21 14:07 bosskmk

@divan did u solve your problem? i have the same problem

Interscope19 avatar Feb 18 '22 21:02 Interscope19

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 avatar Oct 15 '22 08:10 realth000

@realth000 , can you indicate a little more detail of your solution, I try to do the same, without success.

conium avatar Oct 26 '22 12:10 conium

@conium try the demo here https://github.com/realth000/demo_plutogrid_getx

realth000 avatar Oct 29 '22 12:10 realth000

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

github-actions[bot] avatar Apr 12 '23 11:04 github-actions[bot]

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

github-actions[bot] avatar Apr 26 '23 11:04 github-actions[bot]

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 avatar May 14 '23 22:05 pragmaticway

@pragmaticway can you provide a detailed example of your implementation please?

Retr0sec7 avatar Jul 19 '23 07:07 Retr0sec7

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(), ), ), ), ], ), ); } }`

agustin-garcia avatar Mar 29 '24 19:03 agustin-garcia