Skip to content

Ability to create a (sub) dimension that when filtered does not propogate out its filter #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vmantese opened this issue Apr 24, 2015 · 3 comments

Comments

@vmantese
Copy link

Say I have a dataset of people. It includes person's name, race,birthcity, and age.

Applying filters across all dimensions is very useful, but sometimes we don't want that.

I want to create a dimension on the data of people's birthcity. I want this particular dimension to filter in(include) only people from St. Louis. The thing is, I don't want this filter to affect the other dimensions(the reason I need a dimension and not a group is because i'm using dc.js dataTables. which does not accept groups). I need this dimension to have all the properties of a normal dimension EXCEPT for the fact that filters applied directly(in the declaration of this sub dimension) to the dimenson do not cross-affect other dimensions. Filters on normal dimensions should STILL filter on this 'sub' dimension.

Let me know if anyone else has wanted something like this, yes I know groups can answer this issue but I need something with the same properties as a dimension EXCEPT outward propagating filters.

If I'm not the only one who wants this and if someone hasn't solved this problem already maybe I'll take a crack at it.
Thanks,
V

@gordonwoodhull
Copy link

dc.js data tables do support groups as dimensions, pretty much by accident. (The coupling between dc.js and crossfilter is very light.)

There is a little bit of info here, and a link to a (complex) example, in this PR: dc-js/dc.js#697. Please try it out and bring any issues to the appropriate dc forums.

@gordonwoodhull
Copy link

@vmantese, if this works for you, you should close the ticket. It seems like more a dc.js (documentation) issue than crossfilter.

@vmantese
Copy link
Author

Here is the solution I used. Works like a charm.

//Prefilter
function preFilter(dim,okey,oval){

                return{

                    top:function(x1){
                        var a1 = dim.top(x1).filter(function(v){
                            return v[okey] === oval;
                        });
                        return a1;
                    },
                    filter:function(x2){
                        dim.filter(x2);
                    },
                    filterAll:function(){
                        dim.filterAll();
                    },
                    filterExact:function(x4){
                        dim.filterExact(x4);
                    },
                    filterFunction:function(x5){
                        dim.filterFunction(x5);
                    },
                    filterRange:function(x6){
                        dim.filterRange(x6);
                    },
                    bottom:function(x7){
                        dim.bottom(x7);
                    },
                    dispose:function(){
                        dim.dispose();
                    },
                    group:function(x9){
                        dim.group(x9);
                    },
                    groupAll:function(x10){
                        dim.groupAll(x10);
                    },
                    remove:function(){
                        dim.remove();
                    }
                };
            }

Hope this helps someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants