1

Rowspan with MVVM. Arraylist in Bean

asked 2015-08-17 11:48:56 +0800

Neus gravatar image Neus
1415 14

updated 2015-08-18 06:36:41 +0800

Hi,

I have a bean like this:

public class MyBean{
    private String id = "";
    private String name = "";
    private Arraylist<SubClass> subclasses = new Arraylist<SubClass>();
}

I want to load a list of this type of beans inside a grid so that the two first cells represents the name and the id and must rowspan the size of the subclasses list. So, for every subclass in each MyBean I have to create one row.

MyBeanId  MyBeanName     SubClassCol1     SubClassCol2
--------  -----------  ---------------  ---------------
                            SC1.1.1             SC1.2.1
    1         N1            SC1.1.2             SC1.2.2
                            SC1.1.3             SC1.2.3
---------------------------------------------------
    2         N2            SC2.1.1             SC2.2.1
---------------------------------------------------
                            SC3.1.1             SC3.2.1
    3         N3            SC3.1.2             SC3.2.2

I want to do this with MVVM. Any idea of how to do it?

Thank you!

EDIT:

I need different rows for each children, not different cells in the same row. Something like...

<listbox model="@load(vm.myBeans)>
  <template name="model" var="myBean" children="@load(each.subclasses)>
    <template name="children" var="item">
      <listitem>
         <listcell value="@load(myBean.MyBeanId)" rowspan="@load(myBean.subclasses.indexof(item) eq 0 ? myBean.subclasses.size : 1)"/>
        <listcell value="@load(myBean.MyBeanName)" rowspan="@load(myBean.subclasses.indexof(item) eq 0 ? myBean.subclasses.size : 1)"/>
        <listcell value="@load(item.SubClassCol1"/>
        <listcell value="@load(item.SubClassCol2"/>
      </listitem>
   </template>
  </template>
</listbox>

zk fiddle example

But this doesn't work. I can't put a template inside a template. But I think with this example you can imagine what I want to achieve

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-08-17 12:04:08 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

updated 2015-08-18 08:02:43 +0800

I have updated a fiddle so you can see it in mvvm.

You just need to call the size of the list : @load(vm.list.size())

very quick without testing :

<template name="model">
    <listitem children="@load(each.sublist)">
        <listcell label="aaaa" ca:rowspan="@load(each.sublist.size())"/>
        <template name="children" var="node">
            <listcell value="@load(node.name)" style="padding-left:10px"/>
        </template>
    </listitem>
</template>

Edit :

Nothing is impossible, but it's easier if you may select the whole thing.

Look at the updated fiddle.

Greetz Chill.

link publish delete flag offensive edit

Comments

Thanks. But I don't know how to create the template to achieve my objective. I would need a template that goes through the MyBean list. And inside this template one that goes through the SubClass list in MyBean. So...for every MyBean I need to create as many items as subclasses in it

Neus ( 2015-08-17 12:13:21 +0800 )edit

And the first two cells of the first line of every MyBean needs a rowspan with the size of its subclasses list

Neus ( 2015-08-17 12:14:33 +0800 )edit

I edited my post to explain my problem

Neus ( 2015-08-18 06:17:58 +0800 )edit

and about the selection of the listbox? need a sublist to be selected or the first list items?

chillworld ( 2015-08-18 07:13:06 +0800 )edit

The first list items. Maybe its a bit complicated for MVVM. When I select a listitem it has to reference the MyBean item, not the subclass. So...Maybe, 5 listitems makes reference to the same bean

Neus ( 2015-08-18 07:28:10 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-08-17 11:48:56 +0800

Seen: 21 times

Last updated: Aug 18 '15

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