GigaTables / reactables

GigaTables is a ReactJS plug-in to help web-developers process table-data in applications and CMS, CRM, ERP or similar systems.
MIT License
144 stars 30 forks source link

bug: GT doesn't update after rows are deleted #97

Closed wangfrombupt closed 6 years ago

wangfrombupt commented 6 years ago

If the user selects a row and delete it, the row in the database does get deleted, but the deleted row is still shown in GT. Only after a refresh operation (by clicking the refresh button of the browser) does the GT's display gets updated and the deleted row is gone. Please fix this bug. Thanks.

arthurkushman commented 6 years ago

On the server you are getting an array of data e.g.: [2,1] with request method DELETE where u need to delete those rows from DB (probably soft delete), GT instantly removes those fields from table and if u will reload table it should get all rows, but without [2,1]. Can't reproduce this behavior - rows are deleting right after pressing Delete btn and pop-up had been disappeared normally. The only reason u see them is GET request with those rows present again.

wangfrombupt commented 6 years ago

This behavior can be reproduced in this way: first, filter the rows by setting a search text in the search box and make sure the rows satisfying the search condition are not the same set of first rows in the original table. For example, if the original rows are a1,a2,a3,b1,b2,b3,c1,c2,c3, the rows after searching are expected to be b1,b2,b3 ; second, select one of the row, say b1, and delete it. Then you will find b2 is still shown in the table although the corresponding record has been deleted from the database.

After debugging GT step by step, I found that selectedRows in the function editorUpdate record the index of rows in the filtered table instead of the row's rowId. The former is 0 since the deleted row is in the first position of the filtered table, the later is the id value of the corresponding record( in my case 466). So the following code in main.js will not work correctly:

if (dataIndices[dataKey] === rowId) { selectedRows.splice(selectedRows.indexOf(key), 1); this.jsonData.splice(key, 1); }

Thus, I thought the root cause of the bug is in the content of seletedRows which should store rowId instead of row index.

BTW, the following code in Editor.js doesn't take failure deletion into consideration, which may confuse the user when records are not deleted successfully from the database but disappear in the GT table(when this bug is fixed). fetch(ajaxUrl, { method: settings.method, body: JSON.stringify(payload), headers: headers, }).then(response => response.json()).then((data) => { editorUpdate(e, dataResp); this.triggerAfter(EditorConstants.EDITOR_EDIT); });

arthurkushman commented 6 years ago

Related to https://github.com/GigaTables/reactables/issues/100 and - https://github.com/GigaTables/reactables/issues/99 Problems solved.