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

The deleted row still displayed on GT when there is a search condition #100

Closed wangfrombupt closed 6 years ago

wangfrombupt commented 6 years ago

Reproduce process:

  1. filter the rows by setting a condition 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 ;
  2. 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

Fixed - https://github.com/GigaTables/reactables/releases/tag/2.3.11