I'm using a data tree to display a list of tasks (and sub tasks). Is it possible within Tabulator to store the data (for ease) with the Parent ID inside of the child?
Instead of parsing the children records through/inside their parents, the records would be parsed separately, but include the Parent ID.
Before
[
{id:1, name:"Billy Bob", age:"12" "_children":[
{id:2, name:"Mary May", age:"1"}, //child rows nested under billy bob
{id:3, name:"Christine Lobowski", age:"42"},
{id:4, name:"Brendon Philips", age:"125", "_children":[
{id:5, name:"Margret Marmajuke", age:"16"}, //child rows nested under brendon philps
{id:6, name:"Frank Peoney", age:"12"},
]},
]},
]
After
[
{id:1, name:"Billy Bob", age:"12"}
{id:2, name:"Mary May", age:"1", parentid:1},
{id:3, name:"Christine Lobowski", age:"42", parentid:1},
{id:4, name:"Brendon Philips", age:"125"},
{id:5, name:"Margret Marmajuke", age:"16", parentid:4},
{id:6, name:"Frank Peoney", age:"12", parentid:4},
]
That would have been a much easier (natural) way to proceed, yet Tabulator does not store Tree items the way you expressed it so there's no choice if you want to display the Tree in a hierarchical manner (the "natural" way will be listed as a flat list by Tabulator).
Related
I have a table with selectable rows. I want to exclude clicks on the "SAS" column from changing the row selection.
var tabledata = [
{name:"Oli Bob", location:"United Kingdom", gender:"male", col:"red", dob:"14/04/1984"},
{name:"Jamie Newhart", location:"India", gender:"male", col:"green", dob:"14/05/1985"},
{name:"Gemma Jane", location:"China", gender:"female", col:"red", dob:"22/05/1982" },
{name:"James Newman", location:"Japan", gender:"male", col:"red", dob:"22/03/1998"},
];
var table = new Tabulator("#example-table", {
data:tabledata,
selectable: true,
columns:[
{title:"Row Num", formatter: "rownum"},
{title:"Name", field:"name", width:200},
{title:"SAS", formatter: "tickCross"} // exclude clicks on this column from changing the selection
],
});
Kind regards, simon
I used a cellClick event on your "SAS" column to handle your need.
Working Demo: https://codesandbox.io/s/exclude-cols-from-row-selection-ikxth5?file=/src/index.js
Not sure if there is any other proper way to achieve that as my solution is kind of a trick. But hope it helps!
I have this data
Country:"USA", Gender:"Male", Count:100
Country:"USA", Gender:"Male", Count:300
Country:"USA", Gender:"Female", Count:200
Country:"USA", Gender:"Non-binary", Count:50
Country:"France", Gender:"Male", Count:10
Country:"France", Gender:"Female", Count:30
Country:"France", Gender:"Female", Count:10
As you can see, I have several lines with the same combination of Country & Gender.
I need to create a new map - group Country & Gender and sum the Count for this group.
I can arrange the map as I wish –
[Country:"USA", Gender:"Male", Count:100]
or
[[Country:"USA", Gender:"Male"]:100]]
My Questions:
How to best create the map for grouping
How to sum the groups
Thanks!
Simple groupBy with some additions:
List data = [
[Country:"USA", Gender:"Male", Count:100],
[Country:"USA", Gender:"Male", Count:300],
[Country:"USA", Gender:"Female", Count:200],
[Country:"USA", Gender:"Non-binary", Count:50],
[Country:"France", Gender:"Male", Count:10],
[Country:"France", Gender:"Female", Count:30],
[Country:"France", Gender:"Female", Count:10],
]
Map groupped = data.groupBy{ [ Country:it.Country, Gender:it.Gender ] }
groupped.each{ group, vals -> group.sum = vals*.Count.sum() }
println groupped.entrySet().join( '\n' )
prints
{Country=USA, Gender=Male, sum=400}=[{Country=USA, Gender=Male, Count=100}, {Country=USA, Gender=Male, Count=300}]
{Country=USA, Gender=Female, sum=200}=[{Country=USA, Gender=Female, Count=200}]
{Country=USA, Gender=Non-binary, sum=50}=[{Country=USA, Gender=Non-binary, Count=50}]
{Country=France, Gender=Male, sum=10}=[{Country=France, Gender=Male, Count=10}]
{Country=France, Gender=Female, sum=40}=[{Country=France, Gender=Female, Count=30}, {Country=France, Gender=Female, Count=10}]
You can grab map's keys:
println groupped.keySet().join( '\n' )
you'll get:
[Country:USA, Gender:Male, sum:400]
[Country:USA, Gender:Female, sum:200]
[Country:USA, Gender:Non-binary, sum:50]
[Country:France, Gender:Male, sum:10]
[Country:France, Gender:Female, sum:40]
Hi i am working on the following graph graph model of the current scenario
i am traversing from school vertex to subject,games and hobbies vertex
so i wrote a below query which is giving me all the student details
g.V().hasLabel("school").as('school').out().hasLabel('class').out().hasLabel('student')
.project('student_name','student_details').by('name').by(project('student_description',"reads","plays","havehobbies")
.by('description')
.by(__.outE('reads').inV().values('subject_name').limit(5).dedup().fold())
.by(__.outE("plays").inV().values('game_name').limit(5).dedup().fold())
.by(__.outE('have_hobby').inV().values('hobby_name').dedup().limit(5).fold()).dedup().fold()).dedup()
output:
[
{
"student_name": "santhosh kurnapally",
"student_details": [
{
"student_description": "very good student with high IQ",
"reads": [
"maths",
"science",
"social"
],
"plays": [
"cricket",
"football"
],
"havehobbies": [
"news paper",
"tv watching",
"cycling"
]
}
]
},
{
"student_name": "santhosh kurnapally",
"student_details": [
{
"student_description": "very bad student with low IQ",
"reads": [
"maths",
"science"
],
"plays": [
"cricket",
"football"
],
"havehobbies": [
"news paper",
"tv watching"
]
}
]
},
{
"student_name": "neerja goswami",
"student_details": [
{
"student_description": "very good student with very high IQ",
"reads": [
"maths",
"science",
"english"
],
"plays": [
"throw ball",
"carroms"
],
"havehobbies": [
"news paper",
"quilling"
]
}
]
}
]
As in the above output "student_name" is repeating and wanted to group by on "student_name"
g.V().hasLabel("school").as('school').out().hasLabel('class').out().hasLabel('student')
.project('student_name','student_details').by('name').by(project('student_description',"reads","plays","havehobbies")
.by('description')
.by(__.outE('reads').inV().values('subject_name').limit(5).dedup().fold())
.by(__.outE("plays").inV().values('game_name').limit(5).dedup().fold())
.by(__.outE('have_hobby').inV().values('hobby_name').dedup().limit(5).fold()).dedup().fold()).dedup()
.group().by('student_name')
but above Query is throwing error as follows
ActivityId : 6fa77108-39e3-4f77-ba09-2a2e6ca80d9a
ExceptionType : GraphCompileException
ExceptionMessage :
Gremlin Query Compilation Error: Column reference R_17["student_name"] cannot be located in the raw records in the current execution pipeline.
Please let me know how to achieve the above requirement
or any other alternative to achieve the above requirement
one can be "i can group by on the student vertex and then move forward with projection later"
in that case my output can be as follows
[
{
"santhosh kurnapally": [
{
"student_description": ["very good student with high IQ","very bad student with low IQ"]
"reads": [
"maths",
"science",
"social"
],
"plays": [
"cricket",
"football"
],
"havehobbies": [
"news paper",
"tv watching",
"cycling"
]
}
]
},
{
"neerja goswami": [
{
"student_description": ["very good student with very high IQ"],
"reads": [
"maths",
"science",
"english"
],
"plays": [
"throw ball",
"carroms"
],
"havehobbies": [
"news paper",
"quilling"
]
}
]
}
]
NOTE: output may not be the exact but the crux is grouping by on the projected values or grouping by and processing the traversal for the each grouped by vertex after group by or any other alternative to achieve it.
please let me know the possibility of the query for the same or any other alternative for this
You should use select step
g.V().hasLabel('School').as('school').
out().hasLabel('Class').out().
hasLabel('Student').
project('student_name', 'student_details').
by('name').
by(project('student_description', 'reads', 'plays', 'havehobbies').
by('description').
by(__.outE('reads').inV().
values('subject_name').limit(5).dedup().
fold()).
by(__.outE('plays').inV().values('game_name').
limit(5).dedup().fold()).
by(__.outE('have_hobby').inV().values('hobby_name').
dedup().limit(5).fold()).
dedup().fold()).
dedup().
group().
by(select('student_name'))
example: https://gremlify.com/vfnvlkfvybc
The code given in the documentation requires the column attribute and the corresponding JSON column mapping. But I have a dataset having 100+columns and I don't want to map them manually. Is there a function in tabulator that creates the table with the original column names given in JSON. I tried SetData Function but it doesn't work. I tried to remove the columns attribute from the below code but it still doesn't work (Tables are not displayed in the web).
Code given in the documentation is not working:
var table = new Tabulator("#example-table", {
index:"age", //set the index field to the "age" field.
});
var tableData = [
{id:1, name:"Billy Bob", age:"12", gender:"male", height:1, col:"red", dob:"", cheese:1},
{id:2, name:"Mary May", age:"1", gender:"female", height:2, col:"blue", dob:"14/05/1982", cheese:true},
]
table.setData(tableData);
Code working only with Column attributes:
var table = new Tabulator("#example-table", {
index:"age", //set the index field to the "age" field.
});
var tableData = [
{id:1, name:"Billy Bob", age:"12", gender:"male", height:1, col:"red", dob:"", cheese:1},
{id:2, name:"Mary May", age:"1", gender:"female", height:2, col:"blue", dob:"14/05/1982", cheese:true},
]
var table = new Tabulator("#example-table", {
data:tableData, //set initial table data
columns:[
{title:"Name", field:"name"},
{title:"Age", field:"age"},
{title:"Gender", field:"gender"},
{title:"Height", field:"height"},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob"},
{title:"Cheese Preference", field:"cheese"},
],
});
Not a function, but a table constructor property:
http://tabulator.info/docs/4.3/columns#autocolumns
Is there a fancy name generator in nodejs to create names like heroku does for creating applications ?
I'm thinking of names like "yellow_birds", "beautifull_summer" and stuff like that.
Otherwise, are there any dictionnary to pickup cool words ?
Not specific to node, but I've found the following haiku generator here. You could adapt it the following way:
function haiku(){
var adjs = ["autumn", "hidden", "bitter", "misty", "silent", "empty", "dry",
"dark", "summer", "icy", "delicate", "quiet", "white", "cool", "spring",
"winter", "patient", "twilight", "dawn", "crimson", "wispy", "weathered",
"blue", "billowing", "broken", "cold", "damp", "falling", "frosty", "green",
"long", "late", "lingering", "bold", "little", "morning", "muddy", "old",
"red", "rough", "still", "small", "sparkling", "throbbing", "shy",
"wandering", "withered", "wild", "black", "young", "holy", "solitary",
"fragrant", "aged", "snowy", "proud", "floral", "restless", "divine",
"polished", "ancient", "purple", "lively", "nameless"]
, nouns = ["waterfall", "river", "breeze", "moon", "rain", "wind", "sea",
"morning", "snow", "lake", "sunset", "pine", "shadow", "leaf", "dawn",
"glitter", "forest", "hill", "cloud", "meadow", "sun", "glade", "bird",
"brook", "butterfly", "bush", "dew", "dust", "field", "fire", "flower",
"firefly", "feather", "grass", "haze", "mountain", "night", "pond",
"darkness", "snowflake", "silence", "sound", "sky", "shape", "surf",
"thunder", "violet", "water", "wildflower", "wave", "water", "resonance",
"sun", "wood", "dream", "cherry", "tree", "fog", "frost", "voice", "paper",
"frog", "smoke", "star"];
return adjs[Math.floor(Math.random()*(adjs.length-1))]+"_"+nouns[Math.floor(Math.random()*(nouns.length-1))];
}
Take a look to these modules:
https://github.com/faker-js/faker, can generate all kinds of fake data, also localised.
https://github.com/weaver/moniker, this one seems to do just what you need.
https://github.com/nodeca/charlatan
https://github.com/boo1ean/casual
https://github.com/seancannon/goby