React-bootstrap-table2: onFilter hook is broken

Created on 13 Aug 2019  路  8Comments  路  Source: react-bootstrap-table/react-bootstrap-table2

Most helpful comment

For me it seems like bug. According to docs it does not require return value. "...called when column filter being triggered. If you return..." https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/filter-props.html#textfilter

I was using it as a handler without return value to update some app state when user changes filter. Now i cant find a solution as onTableChange works only in remote mode.

All 8 comments

I found the problem : it is not a hook but a customFilter :)

We must take the filtered data in second parameter and return a filtered collection :

onFilter: (filterVal, data) {
  return data.filter(elmt => elmt.includes(filterVal))
}

To conclude it is just a matter of documentation :)

One remark : onFilter is not called when the text in the input is deleted.

Is it normal ?

For me it seems like bug. According to docs it does not require return value. "...called when column filter being triggered. If you return..." https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/filter-props.html#textfilter

I was using it as a handler without return value to update some app state when user changes filter. Now i cant find a solution as onTableChange works only in remote mode.

hum...

image

This is why onFilter is not called when manually clear filter

@jendamozna The workaround is to listen input change is to use the onInput Event Attribute because onChange is already used.

https://www.w3schools.com/tags/ev_oninput.asp

textFilter({
  dataField: 'id',
  text: 'id',
  onInput: function(e) {
    // our code here
  }
});

We can do this because of :

https://github.com/react-bootstrap-table/react-bootstrap-table2/blob/master/packages/react-bootstrap-table2-filter/src/components/text.js#L110

image

Thanks, onInput is working fine. Applicable also on selectFilter().

it's a regression issue from last version, I will fix it soon

ref: https://github.com/react-bootstrap-table/react-bootstrap-table2/pull/1032/files

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eylonronen picture eylonronen  路  3Comments

nskiro picture nskiro  路  4Comments

saifulss picture saifulss  路  4Comments

primakashi picture primakashi  路  3Comments

bogannathan picture bogannathan  路  4Comments