[英]D3js filter table
I'm workin in a table filter with D3js, and I'm close to get it right.我正在使用 D3js 进行表格过滤器,并且我已经接近正确了。 the filter is partially working, it sometimes return the right data and sometimes it doesn't过滤器部分工作,它有时会返回正确的数据,有时它不会
here I get all the data:在这里我得到所有数据:
here the filter is working:这里过滤器正在工作:
but here it doesn't work:但在这里它不起作用:
if I delete all the filters it brings me all the data, which is ok.如果我删除所有过滤器,它会给我带来所有数据,这没关系。
This is how I'm doing the filter at this moment.这就是我现在做过滤器的方式。 I have an example here我这里有一个例子
function updates(selectedGroup){
if (selectedGroup.length>0){
dataFilter = data.filter(function(d,i){if (selectedGroup.includes(d.Departamento? d.Departamento : 0)){return d};});
}else {
dataFilter=data
}
var rows = tbody.selectAll("tr")
.data(dataFilter);
rows.exit().remove();
var rowsEnter = rows.enter().append('tr')
.selectAll("td")
.data(function(row) {
return columns.map(function(column) {console.log('entro');
return {column: column, value: row[column]?row[column]:0};
});
})
.enter()
.append("td")
.attr("style", "font-family: Courier") // sets the font style
.html(function(d) {return d.value? d.value : 0; });
}
Right now you have just an "enter" selection, but nothing changing your "update" selection, which would be like this:现在你只有一个“输入”选择,但没有改变你的“更新”选择,就像这样:
rows.selectAll("td")
.data(function(row) {
return columns.map(function(column) {
return {
column: column,
value: row[column] ? row[column] : 0
};
});
})
.html(function(d) {
return d.value ? d.value : 0;
});
Here is your forked code: https://plnkr.co/edit/OJvAOwiP18VXKZkT?open=lib%2Fscript.js&preview这是您的分叉代码: https://plnkr.co/edit/OJvAOwiP18VXKZkT?open=lib%2Fscript.js&preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.