pluto_grid icon indicating copy to clipboard operation
pluto_grid copied to clipboard

How to remove or refresh table?

Open SittiphanSittisak opened this issue 3 years ago • 4 comments

Hi, I want to replace all rows with new data. For the example, I create a table widget that will return PlutoGrid, and this widget required List<PlutoRow> rows like this.

Widget tableForm({
  required List<PlutoRow> rows,
})

It's used on the main page like this below.

tableForm(rows: rowsInMainPage)

On the main page, I have a button to fetch new data and replace data in rowsInMainPage parm. This onTab function looks like this below.

void replaceRows() {
    setState(() {
      rowsInMainPage = [];
      rowsInMainPage = newDataFromAnotherFunction;
    });
  }

But it does not work. The data are changed but the row does not change, How to make it work?

SittiphanSittisak avatar Apr 09 '22 03:04 SittiphanSittisak

Now, I change the widget to class like this below.

Widget tableForm({
  required List<PlutoRow> rows,
})

to

class TableForm {
  PlutoGridStateManager? stateManager;
  Wdiget showTable(){ ... }
  void createColumn({ required List<TableColObj> columnTitle }){ ... }
  void createRow({ required List<List<TableRowObject>> rowData }){ ... }
}

And I use the remove and append function in createRow() like this below.

try {
      stateManager!.removeRows(stateManager!.rows);
      rows = rowData
          .where((e) => e.length >= columnTitleLength)
          .map((e) => createPlutoRow(list: e))
          .toList();
      stateManager!.appendRows(rows);
    } catch (e) {
      rows = rowData
          .where((e) => e.length >= columnTitleLength)
          .map((e) => createPlutoRow(list: e))
          .toList();
    }

On the main page, I am using this class like this below.

TableForm tableForm = TableForm();

Future getDataFromApi() async {
    rowData = fetchAndFormatData;
    tableForm.createRow(rowData: rowData);
  }

@override
  void initState() {
    tableForm.createColumn(columnTitle: columnTitle);
    getDataFromApi();
    super.initState();
  }

This method can replace all rows(old data) with new rows(new data). If you added something that can fix this issue better than my method. Please share it. https://user-images.githubusercontent.com/59549741/162559604-47e4f9e9-517a-4306-896a-c1d6d7d27c3f.mp4

SittiphanSittisak avatar Apr 09 '22 06:04 SittiphanSittisak

hi @SittiphanSittisak how you add below Footer since the default one looks different

image

kw2019ltd avatar Apr 17 '22 13:04 kw2019ltd

This is custom with simple widget like Container, DropdownButton, Text, IconButon. :)

hi @SittiphanSittisak how you add below Footer since the default one looks different

image

This is custom with simple widget like Comtainer, DropdownButton, Text, IconButon. :)

SittiphanSittisak avatar Apr 17 '22 17:04 SittiphanSittisak

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

github-actions[bot] avatar Jul 30 '22 11:07 github-actions[bot]

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

github-actions[bot] avatar Aug 15 '22 11:08 github-actions[bot]