Handsontable example
HTML
<input id="search_field4" type="search" placeholder="Search">
<p><span id="resultCount">6</span> results</p>
<div id="example4" class="hot handsontable htColumnHeaders"></div>
CSS
</style><!-- Ugly Hack due to jsFiddle issue -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/handsontable.full.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/handsontable.full.min.css">
JavaScript
var
data = [
["Tesla", 2017, "black", "black"],
["Nissan", 2018, "blue", "blue"],
["Chrysler", 2019, "yellow", "black"],
["Volvo", 2020, "white", "gray"]
],
example4 = document.getElementById("example4"),
hot4, searchFiled4, resultCount,
searchResultCount = 0;
function searchResultCounter(instance, row, col, value, result) {
const DEFAULT_CALLBACK = function(instance, row, col, data, testResult) {
if(col === 0){
instance.getCellMeta(row, col).isSearchResult = testResult;
}
};
DEFAULT_CALLBACK.apply(this, arguments);
if (result) {
searchResultCount++;
}
}
hot4 = new Handsontable(example4,{
data: data,
colHeaders: true,
search: {
callback: searchResultCounter
}
});
searchFiled4 = document.getElementById('search_field4');
resultCount = document.getElementById('resultCount');
Handsontable.dom.addEvent(searchFiled4, 'keyup', function(event) {
searchResultCount = 0;
var search = hot4.getPlugin('search');
var queryResult = search.query(this.value);
console.log(queryResult);
resultCount.innerText = searchResultCount.toString();
hot4.render();
});