Custom column filtering with Handsontable?

What I'm looking for is a function to search for individual columns (this particular datatables is an example table) for the plugin for Handsontable mobile tables.

What already exists and was developed by the Handsontable team:

  • Multiple Excel-like filtering (but included in the PRO version). The disadvantages of my case are that it is not free, and it is not quite suitable for what I am looking for.
  • Highlighting cells (cells) or rows (rows) based on user input - Con is what I need to display only the corresponding rows (rows)

Is there such a thing as displaying only the corresponding rows (rows) based on multiple user inputs using Handsontable?

0
source share
1 answer

Based on the solution of this blog , I was able to code the solution.

Check out this JS script that meets all my requirements.

The main function I was looking for is the following:

// The function push every row satisfying all the input values into an array that is loaded 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); } 

What I did was synchronize the row table with the input fields (searchFields), compare the data of each row between the inputs and their corresponding column, and insert the corresponding rows (rows) into the array in order to ultimately display the result of the array. This function is called for any change to the input fields that result in real-time filtering of the table.

Please note that I tried my solution for ~ 10k strings and their problem is not related to Chrome, Firefox and IE.

Also note that I managed to find a solution to keep the currently displayed table in sync with the original data when the values ​​change , but this is IMO from the scope of this question. Please let me know in the comments if you are interested in this.

+1
source

Source: https://habr.com/ru/post/981944/


All Articles