0

Problem with dyanmic columns and rows in a grid [closed]

asked 2013-01-30 21:14:13 +0800

GEdelmann gravatar image GEdelmann
5 1

I have a probleem when trying to layout my grid. Actually it should have one header row and one header column. The number of possible rows AND columns are dynamic.

A short eaxmple: (left all out what is not relevant)

<grid model="@bind(vm.listPermissionRows)">
    <columns>
        <column hflex="2" label="Subjects" />   
        <column forEach="${vm.listActions}" label="${each.name}" />  
    </columns>
    <rows>
    <template name="model" var="prow">
        <row children="@bind(prow.permissionList) @template('created')">
            <!-- THIS DOESNT SHOW UP -->
            <label value="@load(prow.subjectName)" />
            <template name="created" var="pm">
                <label value="dummy"/>
            </template>
        </row>
    </template>
    </rows>
</grid>

As you can see, this doesnt work, the label will be ignored, only the template is beeing used. But how to solve my problem? I cant use a div as a wrapper for my children, as this would group all items in one column. I am clueless. Any ideas?

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by sjoshi
close date 2013-02-12 04:51:58

Comments

I tried <ZK>...</ZK>... the zk part is ignored completely :(

GEdelmann ( 2013-01-31 16:57:22 +0800 )edit

children-binding will clear first then generate and template basically is not a component (more like a definition), so children-binding has no information to know where(which position) to create the children

dennis ( 2013-03-07 03:51:07 +0800 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2013-02-01 10:06:51 +0800

khcyt gravatar image khcyt
216 1

With inclusion of a column model I can suggest the following solution. A little esoteric, but maybe useful for inspiration.

Kai

<zscript><![CDATA[
    ListModelMap data= new ListModelMap();

    java.util.List value= new java.util.ArrayList();
    value.add("entry 01-01"); value.add("entry 01-02"); value.add("entry 01-03");
    data.put("row 01", value);

    value= new java.util.ArrayList();
    value.add("entry 02-01"); value.add("entry 02-02"); value.add("entry 02-03");
    data.put("row 02", value);

    value= new java.util.ArrayList();
    value.add("entry 03-01"); value.add("entry 03-02"); value.add("entry 03-03");
    data.put("row 03", value);

    class VM
    {
        private ListModel columns_model= new ListModelList();
        public VM()
        {
            columns_model.add(new String("Fix 1"));
            columns_model.add(new String("Fix 2"));

            int n_var= ((java.util.List) data.entrySet().iterator().next().getValue()).size();
            for (int i= 0; i< n_var; ++i)
                columns_model.add(new String("Var "+ String.valueOf(i+1)));
        }

        public ListModel getColumnsModel()      { return columns_model; } 
        public ListModel getMapModel()      { return data; } 
    }
]]></zscript>

<window id="win" title="Mix fixed and variable size of column" border="normal" width="600px" 
        apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('VM')" >                 
    <grid id="grid" model="@load(vm.mapModel)">
        <columns children="@load(vm.columnsModel)">
            <template name="children">
                <column hflex="1" label="@load(each)"/>
            </template>
        </columns>
        <template name="model" var="cur_row">
            <row children="@load(vm.columnsModel) @template(forEachStatus.index lt (vm.columnsModel.size()- cur_row.value.size()) ? 'fixed' : 'variable')">
                <template name="fixed">
                    <cell>
                        <label value="@load(0 eq forEachStatus.index ? 'fix entry' : cur_row.key)"/>
                    </cell>
                </template>
                <template name="variable">
                    <cell>
                        <label value="@load(cur_row.value[forEachStatus.index- vm.columnsModel.size()+ cur_row.value.size()])"/>
                    </cell>
                </template>
            </row>
        </template>
    </grid>
</window>
link publish delete flag offensive edit
0

answered 2013-01-31 10:04:17 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2013-03-08 08:48:59 +0800

Current template children binding doesn't support this usage. If the value won't change, please using forEach.

<row>
    <label value="@load(prow.subjectName)" />
    <zk forEach="@load(prow.permissionList)">
        <label value="dummy"/>
    </zk>
</row>
link publish delete flag offensive edit
0

answered 2013-02-12 00:06:46 +0800

GEdelmann gravatar image GEdelmann
5 1

thanks Kai, this is working :) despite beeing a bit awkward to maintain but then, who care.. never change a running zul...

link publish delete flag offensive edit

Question tools

Follow
2 followers

RSS

Stats

Asked: 2013-01-30 21:14:13 +0800

Seen: 148 times

Last updated: Mar 08 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More