Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search implementation? #256

Open
mspanish opened this issue Jul 5, 2020 · 3 comments
Open

search implementation? #256

mspanish opened this issue Jul 5, 2020 · 3 comments

Comments

@mspanish
Copy link

mspanish commented Jul 5, 2020

While I can certainly make my own, I was wondering if anybody has done a search feature for Cheetah Grid? If I stick with this grid I'll post my solution, still trying to make sure everything else works ok. It is VERY fast compared to other grids!

@ota-meshi
Copy link
Member

Thank you for the feature proposal.

I think that it useful if the search API is added to this grid, as you say. But I haven't come up with a way to do the search fast. If you know a good way please let me know.

This grid has a filtering API.
https://future-architect.github.io/cheetah-grid/documents/api/js/grid_data/FilterDataSource.html
This is faster than simply filtering because it pauses when it finishes filtering the visible rows.

@mspanish
Copy link
Author

mspanish commented Jul 6, 2020

Ah yes sorry I did see that after posting the question. I'm not sure if filtering looks through all records or not - you could certainly search through the data w/ a script and then just update the view - maybe you are already doing that. In my case I right now I'm loading Twitter followers, so I'd like to search for a term like maybe "MD" - and then everybody with "MD" in their handle, name, or description would remain, and all other rows would be hidden. I'll see how the filter behaves to see if it can do that.

@mspanish
Copy link
Author

mspanish commented Jul 6, 2020

Your filter works perfectly. The only thing I needed to add was a switch for strings to be lowercase, as otherwise many searches will fail to to a capital letter.

const input = document.querySelector('.filter-value');
input.addEventListener('input', () => {
  console.log('input '+input.value)
  const filterValue = input.value;
  filterDataSource.filter = filterValue ? (record) => {
    // filtering method
    for (const k in record) {
      let val = record[k];
      if (typeof val == 'string') val = val.toLowerCase();
      if ((`${val}`).indexOf(filterValue) >= 0) {
        return true;
      }
    }
    return false;
  } : null;
  // Please call `invalidate()`
  grid.invalidate();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants