1

How can we change Listcell position Dynamically in Listbox? [closed]

asked 2012-12-03 13:06:34 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Can it possible to change the listcell position dynamically? Let us suppose i will create a position attribute for listcell ,now if position will be 1 then it will be first cell and if position is 9 it will be the ninth cell dynamically? Can this type of scenario possible with Listbox in the ZUL page

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-08 06:41:55

8 Replies

Sort by ยป oldest newest

answered 2013-01-09 05:36:38 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

updated 2013-01-22 08:19:16 +0800

Hi vincentjian, Thanks it can be a Solution but its hard to implement this Solution in real world application(because in my case when user click on reorder first a duallistbox will open user will select some headername then only that header with cell will display to user not all) may be i am not able to explain my issue clearly . Let me Give me an example go to Here and click on image(Green image with + sign) here they are doing column Reordering i did this thing with item rendered but its very hectic because i am listbox 1000 of places in my project and everyone have to write implement the getitemrendered() its own way which is increasing code as well as code management issue so i was trying to extend current Listbox and want to add Some more attribute so that it will work fine with reordering .

I have wrote some code but its too ugly write now..You can check Here in fiddle i dont know why it is not getting the* HeaderText.java* file but in my local it is working but again code is very bad right now can you suggest something?

I have Done it Here

link publish delete flag offensive edit

answered 2012-12-04 04:27:00 +0800

vincentjian gravatar image vincentjian
2245 6

updated 2013-01-02 07:57:07 +0800

Do you use ItemRenderer? If yes, I think it is possible to dynamically set different renderer to listbox based on specific scenario.

link publish delete flag offensive edit

answered 2012-12-04 05:55:23 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Acually i have done this from getItemrendered() but then developer have to write lots of code so i will want to see if this thing we can do in ZUl page with static Listcell define inside zul file

link publish delete flag offensive edit

answered 2013-01-02 08:20:40 +0800

vincentjian gravatar image vincentjian
2245 6

Hi

Sorry for reply late. I think there is no other way to change listcell position dynamically in zul page. Using ItenRenderer is probably the best way currently.

link publish delete flag offensive edit

answered 2013-01-02 09:53:32 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

But itemrendered increase code lots of line which is not looking good aproach also data binding is very hard with itemrendered

link publish delete flag offensive edit

answered 2013-01-08 07:56:02 +0800

vincentjian gravatar image vincentjian
2245 6

Hi,

If you are using MVVM with template, then you can change template dynamically with the following pseudo code:

if (position1)
    listbox.setTemplate("model",new CustomTemplate1());
if (position2)
    listbox.setTemplate("model",new CustomTemplate2());

where CustomTemplate can define different listcell position.
Currently, no matter using MVC or MVVM, you have to write if-clause statement to implement this feature.

link publish delete flag offensive edit

answered 2013-01-08 09:55:06 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Hi vincentjian,
Do you know fiddle any link where someone using it?

link publish delete flag offensive edit

answered 2013-01-09 02:56:47 +0800

vincentjian gravatar image vincentjian
2245 6

Hi sjoshi,

I found another solution using @template in zul that seems better than using itemRenderer.
Please refer to @template
Here is the sample code:

test.zul
<zk>
	<div apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('demo.TestVM')">
		<listbox id="lbx" model="@load(vm.items) @template(vm.position eq 'default' ? 'model' : 'model2')">
			<template name="model" var="item">
				<listitem>
					<listcell label="@load(item.name)" />
					<listcell label="@load(item.description)" />
				</listitem>
			</template>
			<template name="model2" var="item">
				<listitem>
					<listcell label="@load(item.description)" />
					<listcell label="@load(item.name)" />
				</listitem>
			</template>
		</listbox>
		<button label="Change Listcell Position" onClick="@command('changePosition')" />
	</div>
</zk>

public class TestVM {

	private List<Item> items = new ArrayList<Item>();
	private String position = "default";
	
	public TestVM() {
		items.add(new Item("Name 1", "Description 1"));
		items.add(new Item("Name 2", "Description 2"));
		items.add(new Item("Name 3", "Description 3"));
		items.add(new Item("Name 4", "Description 4"));
		items.add(new Item("Name 5", "Description 5"));
	}

	public List<Item> getItems() {
		return items;
	}
	
	public String getPosition() {
		return position;
	}
	
	@Command @NotifyChange("position")
	public void changePosition() {
		position = "pos2";
	}
	
	public class Item {
		private String name;
		private String description;
		
		public Item(String name, String description) {
			this.name = name;
			this.description = description;
		}
		public String getName(){return name;}
		public String getDescription(){return description;}
	}
}

link publish delete flag offensive edit

Question tools

Follow

RSS

Stats

Asked: 2012-12-03 13:06:34 +0800

Seen: 176 times

Last updated: Jan 22 '13

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