用于过滤手表的代码 [英] code for filtering handsontables

查看:138
本文介绍了用于过滤手表的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅此问题



ZekeDroid wrotes:

从这里隐藏不匹配的行,变得困难。我所做的就是编写一个简单的函数。

但是抓了几个小时,我没有找到任何代码。

我只提供一个只读表格,但有许多行。我不知道如何自己编写一个插件。

更具体:
您在2月份与Micheael B讨论了过滤器问题,你写了
,你已经使用搜索插件写了一些代码。而且在我看来,Michael已经使用了它的一些问题。

反过来,在我看来,迈克尔可以访问你的代码,即使在那里在你的答案中没有链接。我正在寻找wwww(整个万维网) - 但是什么也没找到。

所以我的主要问题是:你能告诉我你的代码吗?



我的要求:我想过滤(只显示)符合搜索
标准的行。为匹配的单元格着色只是一件好事。如果
有2个命中并且该表有1000个行,那么只有
着色在handsontable示例中并不是真正有意义的。

解决方案

参考我的问题,它与这个相似,但我也想单独过滤列。



我设法编写了一个解决方案,您可以在我自己的Q / A中找到。

你的情况,如果你想要隐藏基于一个搜索条件的无关行的代码,主函数将如下所示:

 函数过滤器(搜索){
var row,r_len;
var data = myData;
var array = []; (col = 0,c_len = data [row] .length; col ) ((''+ data [row] [col])。toLowerCase()。indexOf(search)> -1){
array.push(data [row]);
break;



hot.loadData(array);



$ b

这个JS小提琴


Please refer this question

ZekeDroid wrotes:

From here out to hide the non-matched rows, it gets tough. What I did was write a simple function that.

But grabbing the web for some hours I didn't found any code.

I will present just a readonly table but with many rows. And I have no idea how to write a plug-in by myself.

to be more specific: You discussed the filter problem on February with Micheael B and you wrote that you has wrote a little code using the search plugin. And it seems to me that Michael has used it with some problems.

And in turn it seems to me that Michael has access to your code, even there is no link in your answer. I'm searching the wwww (the whole world wide web) - but found nothing.

So my main question is: can you show me your code?

My request: I want to filter (shows only) the rows which match the search criteria. To colorize the matched cells is only a nice-to-have. Only colorizing as in the handsontable examples is not really meaningful if there are 2 hits and the table has 1000 rows.

解决方案

Refer to my question which is similar to this one but I also wanted to filter the column individually.

I did manage to code a solution that you will find in my own Q/A.

So in your case, if you want the code that hide the irrelevant row(s) based on one search criteria , the main function will look like this :

function filter(search) {
    var row, r_len;
    var data = myData;
    var array = [];
    for (row = 0, r_len = data.length; row < r_len; row++) {
        for(col = 0, c_len = data[row].length; col < c_len; col++) {
            if(('' + data[row][col]).toLowerCase().indexOf(search) > -1) {
                array.push(data[row]);
                break;
            }
        }
    }
    hot.loadData(array);
}

Find the complete solution in this JS Fiddle

这篇关于用于过滤手表的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆