0

Can I add a Listbox as child to a Listitem when the Listitem is selected? I'm currently working with hybris and the code I've tried is this :

    Listitem listitem = new Listitem();
    listitem.setValue(123);
    listitem.setParent(this.secondListBox);
    this.secondListBox.addItemToSelection(listitem);

And

 private EventListener<Event> getListBoxListener() {
    return (event -> {

        this.listBox.getSelectedItems().forEach(listItem -> {
            listItem.appendChild(this.secondListBox);
        }); 
     });
}

(The code shown is just for testing purposes !)

I want to achieve some expandable list for every Listitem with this approach, but I get this error :

Unsupported child for listitem: < Listbox null>

I know that the error already answers my question, but is there another way to do this? Thank you.

user1234SI.
  • 1,812
  • 1
  • 8
  • 22
  • Maybe you should look at Grid - Master Detail? Check the [demo](https://www.zkoss.org/zkdemo/grid/master_detail) and the [documentation](https://www.zkoss.org/wiki/ZK_Component_Reference/Data/Grid/Detail). – Col Feb 11 '20 at 08:56
  • It could be a solution, but it would be too much work for what I want to achieve. (I'm not lazy, but I want to find a simpler solution) – user1234SI. Feb 11 '20 at 09:05
  • 1
    Without knowing exactly what you are trying to achieve another option could be to use a [bandbox](https://www.zkoss.org/zkdemo/combobox/customizable_combobox) – Col Feb 11 '20 at 09:33
  • Your link helped me finding what I was trying to achieve. [This](https://www.zkoss.org/zkdemo/listbox/list_group). Now I'm trying to implement it, thank you for your help :) – user1234SI. Feb 11 '20 at 10:00

1 Answers1

0

<listitem> supports <listcell> children, which then allow arbitrary child components. So you simply have to create a listcell around the nested listbox.

<listbox>
  <listhead>
    <listheader label="outer"/>
  </listhead>
  <listitem>
    <listcell>
      <listbox>
        <listhead>
          <listheader label="nested"/>
        </listhead>
        <listitem label="nested"/>
      </listbox>
    </listcell>
  </listitem>
</listbox>

runnable on zkfiddle

or in your case:

Listcell cell = new Listcell();
cell.appendChild(this.secondListBox);
listItem.appendChild(cell);

however you can't add the same "secondListbox" instance to multiple listcells. You'll just move it around and it will stick to the last listcell parent you append it to.

cor3000
  • 936
  • 1
  • 6
  • 16