PDA

View Full Version : Unable to set style using TreeGridCellRenderer



mathaj77
16 Aug 2009, 11:26 PM
Hi,

I wanted to set a style for Tree Grid using TreeGridCellRenderer .Here is my code but this doesn't work




TreeGridCellRenderer<ModelData> IdRender = new TreeGridCellRenderer<ModelData>()
{
public String render(ModelData model, String property, ColumnData config, int rowIndex,
int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {

String IdVal = (String) model.get(property);
if(IdVal.indexOf('-') > -1){
Date actualDate = DateTimeFormat.getFormat("yyyy-MM-dd").parse((String)model.get("start_dt"));
Date expectedDate = DateTimeFormat.getFormat("yyyy-MM-dd").parse(IdVal.substring(IdVal.indexOf('-')+2,IdVal.lastIndexOf(')')-1));
String style = expectedDate.getTime() < actualDate.getTime() ? "red" : "black";
return "<span style='color: "+style+" '>" + IdVal + "</span>" ;
}else
return IdVal;


}

};


ColumnConfig myId = new ColumnConfig("my_id", "My ID", 100);

myId.setRenderer(IdRender);

Arno.Nyhm
19 Aug 2009, 1:41 AM
this codesnippet works so i would focus more on your calculations!


TreeGridCellRenderer<ModelData> IdRender = new TreeGridCellRenderer<ModelData>() {

public String render(ModelData model, String property, ColumnData config, int rowIndex,
int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {

String IdVal = (String) model.get(property);
// if (IdVal.indexOf('-') > -1) {
// Date actualDate = DateTimeFormat.getFormat("yyyy-MM-dd").parse((String) model.get("start_dt"));
// Date expectedDate = DateTimeFormat.getFormat("yyyy-MM-dd").parse(IdVal.substring(IdVal.indexOf('-') + 2, IdVal.lastIndexOf(')') - 1));
// String style = expectedDate.getTime() < actualDate.getTime() ? "red" : "black";
String style = "red";
return "<span style='color: " + style + " '>" + IdVal + "</span>";
// } else {
// return IdVal;
// }


}
};