从父组件传递的vue-tables-2过滤参数

时间:2018-10-30 14:34:46

标签: vue.js vuejs2 vue-tables-2

是否可以在外部对vue-tables-2中的客户端表使用默认过滤?

我有一个包含多个vue表的父组件,并且希望能够将字符串从父组件传递到所有子组件,每个子组件都包含一个vue表的实例。

1 个答案:

答案 0 :(得分:0)

通过尝试保留所有逻辑客户端,我想我将在原始表数据和vue表之间创建一个层,并将我的逻辑作为计算函数应用于其中。

编辑-它起作用。

这就是我对计算部分所做的

computed: {
        searchRows: function () {
            var filteredRows = this.rows;
            var term = this.searchTerm;
            if(this.searchTerm) {
                filteredRows = [];
                this.rows.forEach(function(entry) {
                    if(String(entry.id).includes(term) || String(entry.name).includes(term)) {
                        filteredRows.push(entry);
                    }
                });
            }
            return filteredRows;
        }
    },

我将表上的数据链接到计算出的调用。

<v-client-table :columns="columns" :data="searchRows" :options="options">

我只能看到的缺点是,如果表足够大,可能会引起问题,因为现在我在内存中最多存储2个副本。