material-table icon indicating copy to clipboard operation
material-table copied to clipboard

Update data when using Remote Data after custom action?

Open calebhypes opened this issue 7 years ago • 2 comments

I have a custom action that is making an API call to my backend to delete data from my database, this in turn removes the item that is being displayed from the database.

How can I get the remote data to be queried again so that Material Table can re-render with the changes applied?

I initially thought to try to re-render the component using a setState change but that doesn't appear to be working. (i can see the state changing accordingly but the table never fetchs the data again)

             {
                  icon: "delete",
                  tooltip: "Delete Partner",
                  onClick: (event, rowData) => {
                    console.log(rowData);
                    let data = {
                      entityId: rowData[0].entityId
                    };
                    fetch("/deleteEntity", {
                      method: "POST",
                      headers: {
                        "Content-Type": "application/json"
                      },
                      body: JSON.stringify(data)
                    }).then(response => {
                      if (response.status === 204) {
                        let index = currentSelectedRows.findIndex(
                          x => x.entityId === rowData[0].entityId
                        );
                        currentSelectedRows.splice(index, 1);
                        this.setState({ currentSelected: currentSelectedRows });
                        console.log("Partner Deleted");
                      } else if (response.status === 500) {
                        console.log("Something went wrong");
                      }
                    });
                  }
                }

calebhypes avatar Apr 11 '19 18:04 calebhypes

@CalebCox

We decided to forward help requests to stackoverflow. Can you ask this question on SO with material-table tag. I or another user will reply it asap.

mbrn avatar Apr 11 '19 18:04 mbrn

@mbrn posted to SO, see here

calebhypes avatar Apr 11 '19 19:04 calebhypes