I have use d3.nest() for group by row values
Code is like this
function createNestingFunction(propertyName){
return function(d){
return d[propertyName];
};
}
var levels = ['first', 'second', 'third']
var nest = d3.nest();
for (var i = 0; i < levels.length; i++) {
nest = nest.key( createNestingFunction(levels[i]) );
}
var root = {
"key":"root",
"values": nest.entries(data) //compute the nest
}
so result will be like this if there are two key ['locationId','userID']
[
{
"key":"12345646", <=== this group by first key locationID
"values": [
{
"key":"asdbnnmb12", <==== this group by second key userId
"values":[]
}
]
},
{
"key":"12345we6", <=== this group by first key locationId
"values": [
{
"key":"hjhggg33", <==== this group by second key userId
"values":[]
}
]
}
]
now how can i identify then only with key ? key is value so what I expect is result like this
[
{
"key":"12345646", <=== this group by first key locationID
"keyArrt":"locationID",
"values": [
{
"key":"asdbnnmb12", <==== this group by second key userId
"keyArrt":"userId",
"values":[]
}
]
}...
]
So i can identify the group by level because I have to redirect page based on grouped level and for that i dded to identify current level.
how can i add this key or any other attr with key and values so on groupby level i can identify them
More: example Just imaging you have social network data and you wanted to build hierarchy like this first level is location and than user and than their related post ( which is actually real row data )
So you will add two key for each level location and user .. it will work well but after getting data you are using this data somewhere in recursive or simple loop how will you identify that current node is user level goupr by or location it will only have key which is actually value not attr, key like location say USA,FRANCE than that level will be show key as USA and FRANCE, so same on user level group by key will be user name like AMIT or any other name .. so based on key we can't decide which group by is this .. so that what i wanted that if key is location value than just add one more attr like key attr and where we just show "location" so after that we can identify that this object have values group-by based on location or user..