How to filter a dataTable in dc.js without affecting other dimensions

爷,独闯天下 提交于 2020-02-04 00:40:07

问题


So for a while I had struggled with how to filter a dataTable in dc.js without affecting other dimensions. This seems counter-intuitive, as it goes against what crossfilter(the data filter behind dc.js) does best, but I'll explain why this can be relevant.

Suppose I have a dataset of peoples name age and gender. In one of my datatables, I only want to display males; using one crossfilter, I would be forced to filter all my other datatables by males.

Suppose I also have a pie chart that lists the first letter of each person's name, and I want to be able to filter on the 'M's. I have a table for males, and a table for females. I don't want these tables to affect the distribution of the pie chart, but I want to be able to click on the pie chart and have it filter the dc.js datatables. More or a less a one way filter.

What is the way to achieve this?


回答1:


dc.js datatables accept crossfilter dimensions. I got around the problem by extending the dimension as follows.

function preFilter(dim,okey,oval){

    return{

        top:function(x){
            var a1 = dim.top(x).filter(function(v){
                return v[okey] === oval;
            });
            return a1;
        }
    };
}

This worked well for me, I hope it can help others.



来源:https://stackoverflow.com/questions/30467215/how-to-filter-a-datatable-in-dc-js-without-affecting-other-dimensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!