Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to invoke standard formatting for ListGridField in custom CellFormatter

    I am using ListGridField.setCellFormatter() to customize the presentation of selected cells in a ListGrid.
    Code:
    field.setCellFormatter(new CellFormatter() {
    	@Override
    	public String format(Object value,
    			ListGridRecord record, int rowNum, int colNum) {
    		if (value==null) return null;
    		String formattedValue = value.toString();
    		Integer count = record.getAttributeAsInt(countFieldName);
    		if (count!=null && count>1)
    			return "<font color=red>" + formattedValue + "</font>";
    		else
    			return formattedValue;
    		}					
    });
    I'd like the "formattedValue" to be the value as it would normally be formatted, just displayed in a red font if the condition is met. But I don't see a way to invoke the standard formatting based on field type.

    Is there some way to get the string with standard formatting already applied and then extend that? Or is there an alternative? Maybe setting just the style for the field? I didn't see anything like that in the API but I may have overlooked it somehow.

    #2
    Since all you really want to do is apply some styling, use an override of getCellCSSText() or getCellStyle() instead. This leaves the built-in formatting intact.

    Comment

    Working...
    X