javatreexulzk

I want to show checkboxes for selected tree nodes only but I am getting radiobuttons for every element in the tree


Here is my code

<?page title="MVVM Tree POC"?>
<zk>
    <borderlayout height="800px">
        <west size="25%"></west>
        <center>
            <window apply="org.zkoss.bind.BindComposer"
                viewModel="@id('vm') @init('com.nagarro.controller.TreeController')"
                title="Dynamic Tree" border="normal">
                <tree multiple="true" checkmark="true" rows="5"
                    model="@bind(vm.employeeTreeModel)">
                    <treecols>
                        <treecol label="First Name" align="center" />
                        <treecol label="Last Name" align="center" />
                        <treecol label="Age" align="center" />
                        <treecol label="Index" align="center" />
                    </treecols>
                    <template name="model" var="node" status="s">
                        <treeitem checkable="true">
                            <treerow style="text-align:center;">
                                <treecell
                                    label="@bind(node.data.firstName)" style="text-align:left;" />
                                <treecell
                                    label="@bind(node.data.lastName)" />
                                <treecell label="@bind(node.data.age)" />
                                <treecell label="@bind(s.index)" />
                            </treerow>

                        </treeitem>
                    </template>
                </tree>

            </window>
        </center>
    </borderlayout>
</zk>

I checked the zkoss reference for the multiple selection property and made the necessary changes in the above zul file. Still it doesnt show checkboxes. Instead it shows only radiobuttons.

Also, I want to show checkboxes in front of some selected tree nodes and not all of them.


Solution

  • Use

    setMultiple(true)
    

    on the model instance returned by vm.employeeTreeModel not the tree it self.

    If you want just some to be checkable, change this

    <treeitem checkable="true">
    

    to something like that

    <treeitem checkable="@load(node.checkable)">