getOpenState

gets the IDs of items in the currently opened group

object getOpenState();
objectthe object with all parents to this level and an array of items from the currently opened group

Example

webix.ui({
    view:"grouplist",
    data:[ //hierarchical JSON dataset
        {id:"root", value:"Films data", open:true, data:[
            { id:"1", open:true, value:"The Shawshank Redemption", data:[
                { id:"1.1", value:"Part 1" },
                { id:"1.2", value:"Part 2", data:[
                    { id:"1.2.1", value:"Page 1" },
                    { id:"1.2.2", value:"Page 1" }
                    ]},
                { id:"1.3", value:"Part 3" }
            ]},
            { id:"2", open:true, value:"The Godfather", data:[
                { id:"2.1", value:"Part 1" }
            ]}
        ]}
});
 
 
var state = $$('grouplist1').getOpenState();
if (state){
    result = JSON.stringify(state);
    webix.message(result);
}
 
/* 
If you open the "root" branch, there go to "1" and then open the "1.2"
{ 
    "parents":["root","1","1.2"],
    "branch":["1.2.1","1.2.2"] 
}
*/

Related samples

Details

The return object contains two properties:

  • parents (array) - the ID of all the parents (parents of the currently opened group from top to bottom);
  • branch (array) - the IDs of the items from the currently opened group.

On the top level with all the groups closed, "parents" will be empty.

If you use non-hierarchical data and form groups (parents) on the go during component init, they get automatically generated IDs.

{
    "parents":["1363185715932"], <- auto ID
    "branch":[125,169,184,189]
}

If needed, every array can be accessed by an object key (e.g. branch to get items in the branch):

function get_children(){
    var state = $$('group').getOpenState().branch; //gets only children
    titles = [];
    for (var i=0; i<state.length; i++){ 
        var id = state[i];
        var title = $$('group').getItem(id).title;
        titles.push(title);
    }
    alert(titles.join(",\n")); //get all the titles of the children
}
See also
  • Articles
  • Back to top
    If you have not checked yet, be sure to visit site of our main product Webix web ui framework and page of javascript library list product.