wenzhixin / bootstrap-table

An extended table to integration with some of the most widely used CSS frameworks. (Supports Bootstrap, Semantic UI, Bulma, Material Design, Foundation, Vue.js)
https://bootstrap-table.com/
MIT License
11.74k stars 4.44k forks source link

`custom-search` and `filterBy` not working in combination (filterBy per row not executed) #6525

Open marceloverdijk opened 2 years ago

marceloverdijk commented 2 years ago

Bootstraptable version(s) affected

1.21.1

Description

When using customSearch and filterBy with a filterAlgorithm function the filterAlgorithm function is not called.

As soon as a custom search is configured filter by won't work anymore...

In below code the filtering and filtering done are logged, but never filtering row.

$('#max-price-filter').on('input', function() {
      const maxPrice = $(this).val()
      if (maxPrice) {
        console.log('filtering')
        $('#table').bootstrapTable('filterBy', {}, {
          'filterAlgorithm': (row, filters) => {
            console.log('will never get into here')
            return parseInt(row.price.slice(1)) <= maxPrice
          }
        })        
        console.log('filtering done')
      } else {
        $('#table').bootstrapTable('filterBy', {}, { 'filterAlgorithm': () => true })
      }
})

The example ref below proves this. When disabling the custom search the filtering row is working.

Example(s)

https://live.bootstrap-table.com/code/marceloverdijk/13480

Possible Solutions

No response

Additional Context

No response

marceloverdijk commented 2 years ago

Maybe this is intended behaviour? and when using a data-custom-search function it cannot be combined with $('#table').bootstrapTable('filterBy', {}, { 'filterAlgorithm': () => ..do some custom filtering.. }) ?

Just to explain what I'm trying to accomplish:

Above works perfectly. But now I want to change the default keywords search (data-search-selector) by a more intelligent fuzzy search. That's why I though just to add a data-custom-search to override the default search function.

To execute the advanced fuzzy search (using fuse.js) I need to have hold of all data; so only having access to the row is not enough. So with filterBy only I cannot solve this unfortunately. What should be the best way to do this?

marceloverdijk commented 2 years ago

I found a way to implement this and here is a full example: https://live.bootstrap-table.com/code/marceloverdijk/13510

This might be useful for others or maybe could be used to be included in the example repo?