无论如何用Handsontable过滤行? [英] Anyway to filter rows with Handsontable?

查看:97
本文介绍了无论如何用Handsontable过滤行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在handsontable的列上添加搜索过滤器.我可以使用搜索插件的callback用CSS隐藏行,但这会中断滚动.搜索插件似乎也只查看表的前100个左右. 是否存在任何将行过滤添加到handsontable的插件?

I'm currently trying to add a search filter on a column in handsontable. I can use the callback of the search plugin to hide the rows with css but that breaks scrolling. The search plugin also seems to only look at the first 100 or so of a table. Is there any plugin that exists that adds row filtering to handsontable?

推荐答案

对我来说,使用Handsontable进行实时过滤有两种情况. 过滤器和/或

For me, their is two cases for a live filtering with Handsontable. A columns filters, and/or search filter.

每列一个字段,允许同时应用多个过滤器:

One filed per column allowing to apply multiple filter at the same time :

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);
}

此JS小提琴中找到工作示例

一个允许在表中任何地方搜索任何值的字段:

A field allowing to search any value anywhere in the table :

function filter(search) {
    var 
    row, r_len,
    data = myData, // Keeping the integretity of the original data
    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);
}

此JS小提琴中找到工作示例

在两种情况下,如果注定要修改数据,则每次应用过滤器时都必须保持原始数据的完整性.您可以参考前两个链接,以了解这两种情况的更多详细信息.

In both case, if the data are destined to be modified, the integrity of the original data must be kept every time a filter is applied. You can refer to the two first links for more details of the two cases.

请注意,两个功能可以合并并同时使用.

Note that both function can be merged and be used at the same time.

这篇关于无论如何用Handsontable过滤行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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