For me, these are two cases for direct filtering using Handsontable. Column filters and / or search filter .
1. Individual column filter
One filed per column, allowing multiple filters to be applied simultaneously:
function filter() { var row, r_len, col, c_len; var data = myData; // Keeping the integrity of the original data var array = []; var match = true; for (row = 0, r_len = data.length; row < r_len; row++) { for(col = 0, c_len = searchFields.length; col < c_len; col++) { if(('' + data[row][col]).toLowerCase().indexOf(searchFields[col]) > -1); else match=false; } if(match) array.push(data[row]); match = true; } hot.loadData(array); }
Find a working example in this JS script
2. Search filter
A field that allows you to search for any value anywhere in the table:
function filter(search) { var row, r_len, data = myData,
Find a working example in this JS script
In both cases, if the data is intended to be modified, the integrity of the source data should be stored every time a filter is applied. You can refer to the first two links for more information on these two cases.
Please note that both functions can be combined and used simultaneously.
source share