Ngx-datatable: Search: do not display irrelevant results

Created on 16 Aug 2016  路  11Comments  路  Source: swimlane/ngx-datatable

Currently, when the name "ethel price" is typed on the example, Ethel Price comes in first position, followed by some rows that should not be here.

It is strange since the filter function works well, returning only the entries the table should display.

I would have thought that the

this.rows.splice(0, this.rows.length);

would remove all the lines before pushing the ones we want, but it seems there is some kind of cache involved.

`updateFilter(val) {
// remove existing
this.rows.splice(0, this.rows.length);

// filter our data
let temp = this.temp.filter(function(d) {
  return d.name.toLowerCase().indexOf(val) !== -1 || !val;
});
// here, the temp array is returning the correct values

// update the rows
this.rows.push(...temp);
// the strangest thing is that console.log(this.rows) has the same correct values as well!!

}`

Bug Investigate

All 11 comments

Perhaps it was related to my virtual scrolling change. Thanks for reporting.

For your information, this does not seem to happen with a smaller data set (ie a single page).

Can u make a plunkr demo?

I'm facing the same issue. I found that this bug reappears if returning results are less than displaying table rows. With @adaur's example, I added one more entry (total of three):
https://plnkr.co/edit/Vx9JsxBSQDyRzyIdsyJW

If search "ethel", the result count should be 1, but the current displaying row count is 3. I found it is going to remove the same amount of rows right below result. In this case, you won't see "Claudine Neal", but "Claudine Neal2" remain on displayed.

More example, https://plnkr.co/edit/U9rmbOebgls8dop6vdOJ
I have two "ethel" entries, and three "Claudine" entries (appended with 1,2,3). If you made a search for "ethel" this time, the result count should be 2. Thus, the two rows right after results will get removed, but whatever rows right after that remains. (so "Claudine Neal3" remain on displayed).

i think this is somehow related to the issue i opened #84
If you use this plnkr:
https://plnkr.co/edit/bvA2gMHyxFtCFN8ZWbi0?p=preview
Now enter 'stein' you got too many results (4), now add a space ('stein )' -> zero results, remove the space again ('stein') now you just got 3 results...

image
image
image

You can repeat the game until just the correct entry is shown.

Hi guys,

Firstly good job on this project, thanks for the work achieved.
I noticed the same issue this morning, after different testing case.

After some investigation, there is some strange behaviour within DataTableBody:DataTableBody.

Some screenshots attached:

When filtering a result, this is the initial state of the (cached?) rows after updateRows is called via this.state.onRowsUpdate.subscribe

screen shot 2016-09-02 at 16 21 42

This is the new set of filtered rows within the data-table parent component

screen shot 2016-09-02 at 16 22 04

I wonder why using the row cached here ? could even replace this.rows with this.state.rows and that should be fine as this.state.rows are the new set of rows, no ?
I guess this.rows are used as 'source of truth' for the pagination, may be should consider having a different behaviour for the filtered rows ?

Thanks,

Ben

Gently bumping this issue because it's quite important

I think this is related to #84

Unfortunately, while using filter and vertical scroll, table shows irrelevant results.
Plnkr: https://plnkr.co/edit/T2ZOFZTsjmA5FooH2JLq?p=preview just type "ethel" in input

Closing due to inactivity and age. If its still an issue, please reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ExTheSea picture ExTheSea  路  3Comments

mmrath picture mmrath  路  3Comments

devendraYebhi picture devendraYebhi  路  3Comments

rotemx picture rotemx  路  3Comments

alceucardoso picture alceucardoso  路  3Comments