I need to be able to add items either above, below or indented under the current user selected item.
I am able to get the index of the current item and am using 2 functions to addBelow or addAbove the current item by incrementing or decrementing the current index number as follows:
function addAbove(ndx) {
console.log('index to add new item above: ' + ndx);
var newId = gridItems.webix_treetable().add({ "id":"99", "type":"item", "action":"Sample Action Item Test", "due":"11/22/2014" }, ndx - 1);
console.log('id of new item above: ' + newId);
gridItems.webix_treetable().refresh();
}
function addBelow(ndx) {
console.log('index to add new item below: ' + ndx);
var newId = gridItems.webix_treetable().add({ "id":"99", "type":"item", "action":"Sample Action Item Test", "due":"11/22/2014" }, ndx + 1);
console.log('id of new item below: ' + newId);
gridItems.webix_treetable().refresh();
}
I would expect the addAbove function to work easily enough but it does not - it adds the new item 2 or 3 rows below - add above has a similar behavior.
Is there a simple way to do what I need to do or do I need to directly manipulate my data object? (i have added that just below)
Is there a way programattically to append an item under the current item so that it is a child of the current item?
Any help would be great and I do appreciate all the help I have received so far!
Thanks
Data object:
var actionItems = [
{ "id":"1", "type":"section", "action":"QDRO 1", "due":"", "open":true, "data":[
{ "id":"2", "type":"subSection", "action":"Sample Action Item 11", "due":"07/22/2014"},
{ "id":"3", "type":"subSection", "action":"Sample Action Item 12", "due":"07/22/2014" }
]},
{ "id":"4", "type":"section", "action":"QDRO 2", "due":"", "open":true, "data":[
{ "id":"5", "type":"subSection", "action":"Sample Action Item 21", "due":"08/22/2014" },
{ "id":"6", "type":"subSection", "action":"Sample Action Item 22", "due":"08/22/2014" }
]},
{ "id":"7", "type":"item", "action":"Sample Action Item 3", "due":"08/22/2014" },
{ "id":"8", "type":"item", "action":"Sample Action Item 4", "due":"08/22/2014" },
{ "id":"9", "type":"item", "action":"Sample Action Item 5", "due":"08/22/2014" },
{ "id":"10", "type":"item", "action":"Sample Action Item 6", "due":"08/22/2014" },
{ "id":"11", "type":"item", "action":"Sample Action Item 7", "due":"08/22/2014" },
{ "id":"12", "type":"item", "action":"Sample Action Item 8", "due":"08/22/2014" },
{ "id":"13", "type":"item", "action":"Sample Action Item 9", "due":"08/22/2014" },
{ "id":"14", "type":"item", "action":"Sample Action Item 10", "due":"08/22/2014" },
{ "id":"15", "type":"section", "action":"QDRO 3", "due":"", "open":true, "data":[
{ "id":"151", "type":"subSection", "action":"Sample Action Item 31", "due":"08/22/2014" },
{ "id":"152", "type":"subSection", "action":"Sample Action Item 32", "due":"08/22/2014" }
]},
{ "id":"116", "type":"item", "action":"Sample Action Item 11", "due":"08/22/2014" },
{ "id":"117", "type":"item", "action":"Sample Action Item 12", "due":"08/22/2014" },
{ "id":"118", "type":"item", "action":"Sample Action Item 13", "due":"08/22/2014" },
{ "id":"119", "type":"item", "action":"Sample Action Item 14", "due":"08/22/2014" },
{ "id":"120", "type":"item", "action":"Sample Action Item 15", "due":"08/22/2014" },
{ "id":"121", "type":"item", "action":"Sample Action Item 16", "due":"08/22/2014" },
{ "id":"122", "type":"item", "action":"Sample Action Item 17", "due":"08/22/2014" },
{ "id":"123", "type":"item", "action":"Sample Action Item 18", "due":"08/22/2014" },
{ "id":"124", "type":"item", "action":"Sample Action Item 19", "due":"08/22/2014" },
{ "id":"125", "type":"item", "action":"Sample Action Item 20", "due":"08/22/2014" }
];