Search code examples
javascriptfuzzy-searchlistjs

ListJS - Count item after search


How to count item after search by input field on ListJS?

I don't know where I can get it, because I just use basic example :

var params = {
  valueNames : ['titleList', 'currentList', 'typeCode', 'categoryCode'],
  plugins: [ ListFuzzySearch() ]
}

var searchSightseeing = new List('sightseeingList', params);

I have try use method size() in oninput my field like this :

$('#sightseeing-name').on('input', function(){
  console.log(searchSightseeing.size());
})

But it still result count of all item.


Solution

  • After a long-long research, I have get an answer.

    to get update on input change use method keyup.

    add searchSightseeing.update().matchingItems.length to get count.

    var params = {
      valueNames : ['titleList', 'currentList', 'typeCode', 'categoryCode'],
      plugins: [ ListFuzzySearch() ]
    }
    
    var searchSightseeing = new List('sightseeingList', params);
    
    searchSightseeing.on('searchComplete', function(){
      console.log(searchSightseeing.update().matchingItems.length);
    });