How to set style for Table components items (rows)

Functionality exists since 4.0.4-rc3.

Method uses the specified property (column) value of each item (row) to create a stylename for the row. The stylename is created by doing toString() on the property value. Spaces and dots are replaced with underscore, no other replacements/filtering is done. Clientside the theme adds a prefix "rowstyle-" to the stylename (to avoid conflicts and allow for numeric styles etc).

Example: The table has a column "status", which is used as itemStyleProperty. The "status" property toString() return some values that are translated: "0" -&gt "rowstyle-0", "1.000 pcs" -&gt "rowstyle-1_000_pcs".

The rows can be styled in CSS as follows:


.itmtk .table tr.rowstyle-0 {
	background-color: red;
}

Testing code (add also some styles to CSS)


Table t;

	public void init() {

		Window main = new Window();
		setMainWindow(main);

		t = new Table();
		t.addContainerProperty("String", Integer.class, new Integer(0));
		t.addContainerProperty("Label", Label.class, new Label("red"));
		t.addContainerProperty("TextField", TextField.class, new TextField());
		t.addContainerProperty("Select", Select.class, new Select());
		for (int i = 0; i &lt 150; i++) {
			Object id = t.addItem();
			Item it = t.getItem(id);
			Property p = it.getItemProperty("String");
			p.setValue(new Integer((int) (Math.random() * 10.0)));
			p = it.getItemProperty("Label");
			if (Math.random() &gt 0.5) {
				p.setValue(new Label("blue"));
			} else {
				p.setValue(new Label("red"));
			}
			p = it.getItemProperty("TextField");
			TextField tf = new TextField();
			tf.setImmediate(true);
			if (Math.random() &gt 0.8) {
				tf.setValue("free");	
			}
			p.setValue(tf);
			p = it.getItemProperty("Select");
			Select sel = new Select();
			sel.setImmediate(true);
			sel.addItem("red");
			sel.addItem("free");
			sel.addItem("blue");
			p.setValue(sel);
		}
		main.addComponent(t);

		Button b = new Button("String", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				t.setItemStylePropertyId("String");
				getMainWindow().requestRepaint();
			}
		});
		main.addComponent(b);

		b = new Button("Label", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				t.setItemStylePropertyId("Label");
				getMainWindow().requestRepaint();
			}
		});
		main.addComponent(b);

		b = new Button("TextField", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				t.setItemStylePropertyId("TextField");
				getMainWindow().requestRepaint();
			}
		});
		main.addComponent(b);
		b = new Button("Select", new Button.ClickListener() {
			public void buttonClick(ClickEvent event) {
				t.setItemStylePropertyId("Select");
				getMainWindow().requestRepaint();
			}
		});
		main.addComponent(b);
	}

Nice feature, just tested. 8)