gregnb / mui-datatables

Datatables for React using Material-UI
MIT License
2.71k stars 934 forks source link

custom filter, removed chip provide wrong `filterPos` when its value is 0 #2017

Open zksteel opened 1 year ago

zksteel commented 1 year ago

Expected Behavior

Consider case where my filterList is [1, 0, 2]. In update function of customFilterListOptions I should get index of removed value. When I remove chip with value 0 (index=1 in provided case), the filterPos should be 1.

Current Behavior

It works properly in almost all casses, but when removed chip/value is 0, filterPos is -1.

Steps to Reproduce (for bugs)

codesandbox: https://codesandbox.io/s/custom-filter-chip-issue-3qtm2x?file=/src/index.tsx

step to reproduce:

  1. Remove User chip

Admin is removed instead.

Your Environment

Tech Version
Material-UI 5.11.15
MUI-datatables 4.3.0
React 18.2.0
browser Chrome

Additional Info

I found that this issue may be caused by this line https://github.com/gregnb/mui-datatables/blob/a382f3e8e850c7fcdd395f8594a5e0afefcaf905/src/components/TableFilterList.js#L63 item[customFilterItemIndex] of value 0 is consider as false and then [] is passed.

Then here https://github.com/gregnb/mui-datatables/blob/a382f3e8e850c7fcdd395f8594a5e0afefcaf905/src/MUIDataTable.js#L1372 value could not be found and -1 is returned;

zksteel commented 1 year ago

Could anyone suggest a quick fix? I need it to work until it will be fixed.