PDA

View Full Version : ListView background items



valery.stroeder
4 Feb 2010, 6:40 AM
Hello,

In my Grids, a row of two is green and the others are white thanks this code :


myGrid.getView().setViewConfig(new GridViewConfig(){
@Override
public String getRowStyle(final ModelData model, final int rowIndex, final ListStore<ModelData> ds) {
String returnTemp;

if(rowIndex%2==0) {
returnTemp = "even";
} else {
returnTemp = "odd";
}
return returnTemp;
}
});


in the style.css file


.even {
background-color:green;
}
.odd {
background-color:white;
}

Is there a way to do the samething in a ListView ?

valery.stroeder
8 Feb 2010, 4:16 AM
Noboday has a solution?

Arno.Nyhm
10 Feb 2010, 9:02 AM
you need to do this via template in XTemplate syntax

valery.stroeder
12 Feb 2010, 7:15 AM
Do you have an example ??

valery.stroeder
24 Mar 2010, 5:32 AM
up?

sven
24 Mar 2010, 5:40 AM
listView.setTemplate(getTemplate());



private native String getTemplate() /*-{
return [
'<tpl for=".">',
'<div class="{[xindex % 2 === 0 ? "even" : "odd"]} x-view-item">{name}</div>',
'</tpl>'
].join("");
}-*/;

valery.stroeder
24 Mar 2010, 5:59 AM
Thank you, it works fine !

If i want use a different kind of condition, for example I have a ComboBox(MyObject) (called combo) and a Map<MyObject,int> (called map).
Can I use my map to conditionally set the style name ?

Something like that?

private native String test() /*-{
return [
'<tpl for=".">',
'<div class="{[xmap.get(currentObject) === 0 ? "redStyle" : "greenStyle"]} x-view-item">{name}</div>',
'</tpl>'
].join("");
}-*/;

valery.stroeder
24 Mar 2010, 6:39 AM
Is it possible with Xtemplate ?
Should I try with another method like onRender or setViewConfig ?
Why doesn't exist a ListViewConfig ?