Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Create hierarchical grid dynamically
posted

Hello,

 

Is it possible to create a hierarchical grid dynamically, with an arbitrary number of Master-Detail levels?

 

Thanks,
Mike

 

  • 12025
    posted

    Hello Mike,

    Yes, you can create any number of hierarchy levels dynamically within the WebGrid. Just created the grid dynamically and add a column that has a master detail grid attached, which will allow the user to expand to the next level. Your code will look something like the following.

    //Create a grid for the level to add

    GridView secondLevelGrid = (GridView) FacesContext.getCurrentInstance().getApplication().createComponent(GridView.COMPONENT_TYPE);

     

    //Setup the secondLevelGridColumns here

     

    //Create a column that will allow user to expand to the next level

    Column masterDetailColumn = (Column) FacesContext.getCurrentInstance().getApplication().createComponent(Column.COMPONENT_TYPE);

     

    //set the master detail facet on the column

    masterDetailColumn.setMasterDetail(secondLevelGrid);

     

    //Add the column that will allow to expand to the next level to the main grid

    grid.getTemplateItems().add(masterDetailColumn);

     

    Hope this helps.

    Taz.