Javascript 制表器-基于另一制表器的过滤
我有一个包含搜索结果的制表器。代码如下:Javascript 制表器-基于另一制表器的过滤,javascript,jquery,json,tabulator,Javascript,Jquery,Json,Tabulator,我有一个包含搜索结果的制表器。代码如下: var table = new Tabulator("#json-table", { layout:"fitDataFill", //initialFilter:[{field:"title", type:"!=", value:"ignoreList.title"}], ajaxURL:tabUrl, ajaxResponse:function(url, params, response){ return
var table = new Tabulator("#json-table", {
layout:"fitDataFill",
//initialFilter:[{field:"title", type:"!=", value:"ignoreList.title"}],
ajaxURL:tabUrl,
ajaxResponse:function(url, params, response){
return Object.values(response);
},
columns:
[{title:"Title", field:"title", align:"center"},
{title:"Price", field:"price", align:"center"},
{title:"Shipping Cost", field:"shippingCost.shippingServiceCost.value", align:"center"},
{title:"Watch List", align:"center", cellClick:function(e, cell){
var data = cell.getData();
watchListArray.push(data);
localStorage.setItem("watchList", JSON.stringify(watchListArray));
},},
{title:"Ignore List", align:"center", cellClick:function(e, cell){
var data = cell.getData();
ignoreListArray.push(data);
localStorage.setItem("ignoreList", JSON.stringify(ignoreListArray));
},
},
{title:"Image", align:"center"},
],
});
ignoreListArray = JSON.parse(localStorage.getItem("ignoreList"));
var ignoreList = new Tabulator("#json-table", {
data:ignoreListArray,
layout:"fitDataFill",
columns:
[{title:"Title", field:"title", align:"center"},
{title:"Price", field:"price", align:"center"},
{title:"Shipping Cost", field:"shippingCost.shippingServiceCost.value", align:"center"},
{title:"Watch List", align:"center"},
{title:"Ignore List", align:"center"},
{title:"Image", align:"center"},
],
});
我还有一个包含忽略列表的制表器。代码如下:
var table = new Tabulator("#json-table", {
layout:"fitDataFill",
//initialFilter:[{field:"title", type:"!=", value:"ignoreList.title"}],
ajaxURL:tabUrl,
ajaxResponse:function(url, params, response){
return Object.values(response);
},
columns:
[{title:"Title", field:"title", align:"center"},
{title:"Price", field:"price", align:"center"},
{title:"Shipping Cost", field:"shippingCost.shippingServiceCost.value", align:"center"},
{title:"Watch List", align:"center", cellClick:function(e, cell){
var data = cell.getData();
watchListArray.push(data);
localStorage.setItem("watchList", JSON.stringify(watchListArray));
},},
{title:"Ignore List", align:"center", cellClick:function(e, cell){
var data = cell.getData();
ignoreListArray.push(data);
localStorage.setItem("ignoreList", JSON.stringify(ignoreListArray));
},
},
{title:"Image", align:"center"},
],
});
ignoreListArray = JSON.parse(localStorage.getItem("ignoreList"));
var ignoreList = new Tabulator("#json-table", {
data:ignoreListArray,
layout:"fitDataFill",
columns:
[{title:"Title", field:"title", align:"center"},
{title:"Price", field:"price", align:"center"},
{title:"Shipping Cost", field:"shippingCost.shippingServiceCost.value", align:"center"},
{title:"Watch List", align:"center"},
{title:"Ignore List", align:"center"},
{title:"Image", align:"center"},
],
});
如果用户单击要忽略的行的“忽略列表”单元格,我将使用localStorage
将搜索结果中的行存储在“忽略列表”列表器中。如果一行被放在忽略列表中,我想让它在将来的搜索结果中永远不会出现,直到它从忽略列表中删除
是否有内置的筛选功能可以帮助我完成这项工作?您需要使用自定义筛选功能来完成这项工作 为了过滤掉这些行,您需要一种方法来比较ignore列表中的行和表中的行。通常,您会为每一行分配一个id字段,然后检查该行的id是否在忽略列表中。我将在示例中使用这种方法,但您可以轻松地调整它,以查找行对象中任何属性的匹配值 在自定义过滤器中,我们将使用JavaScript数组中内置的过滤器函数查找数组中的任何匹配项
function customFilter(data, filterParams){
//data - the data for the row being filtered
//filterParams - params object passed to the filter
//check for matches
var matches = ignoreListArray.filter(function(element){
return element.id == data.id
});
return !matches.length; //allow row if it does not match any row in the ignore list
}
//set filter on table
table.setFilter(customFilter);
有关使用自定义筛选器的详细信息,请参见,您需要使用自定义筛选器来实现此目的 为了过滤掉这些行,您需要一种方法来比较ignore列表中的行和表中的行。通常,您会为每一行分配一个id字段,然后检查该行的id是否在忽略列表中。我将在示例中使用这种方法,但您可以轻松地调整它,以查找行对象中任何属性的匹配值 在自定义过滤器中,我们将使用JavaScript数组中内置的过滤器函数查找数组中的任何匹配项
function customFilter(data, filterParams){
//data - the data for the row being filtered
//filterParams - params object passed to the filter
//check for matches
var matches = ignoreListArray.filter(function(element){
return element.id == data.id
});
return !matches.length; //allow row if it does not match any row in the ignore list
}
//set filter on table
table.setFilter(customFilter);
有关使用自定义筛选器的完整详细信息,请参见