Announcement

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

    Boolean ListGridField with CellFormatter

    Hello,

    I'm creating a new ListGridField of ListGridFieldType.BOOLEAN which renders in the non-editable grid as a checkbox item on the filter header and in its rows. The title of the column is align in center.
    That's all good, but it doesn't do anything yet.

    I add a setCellFormatter and tried returning "true"/"false" or "1"/"0" (a function by checking another field in the incoming record) but when I do that, I lose the checkbox items in the rows (not in the filter header), everything in the column is aligned left and the values come up as my String ("true"/"false").
    Probably because the cellFormatter function expects raw html, I realized.
    So I then wrapped the value in a CheckBoxItem, added that to a DynamicForm and returned the innerHTML of that form.

    That works, thought I can't get the alignment correct. But I'm wondering if this is the best approach, as it sounds overkill.

    #2
    Yes, that's overkill. It's not clear what you're trying to do (so far you've just described behavior that's already built in) but look at overriding getValueIcon as part of the solution.

    Comment


      #3
      I thought so. But how can I add a column to a ListGrid without adding values for my boolean column in the records?

      I want to add a ListGridField clientside which - to know its value - looks at other fields in the records, but doesn't exist itself in the record as a field.

      Comment


        #4
        So again, an override of getValueIcon() for a boolean field would be a way to just return the URL for true/false images without writing a full formatter. If this is somehow not enough, use a CellFormatter, but there's no need to use getInnerHTML() from any FormItem, just return an <img> tag. The Canvas.imgHTML() helper method can do most of the work for you.

        Comment


          #5
          Ok understood.
          The API docs speak of com.smartgwt.client.widgets.grid.ListGridField#getValueIcons but there is no such method yet. Do I create a code.google issue for it?
          I'd rather not use com.smartgwt.client.widgets.grid.ListGrid#getValueIcon to keep code together.

          Comment


            #6
            The latest nightlies support setValueIconMapper() which is the SGWT override of the SC getValueIcon method.

            Comment


              #7
              Let me correct my last post. There is a setValueIconMapper method for a FormItem, not a ListGridField. To do something similar in a LG there is a LG method that can be overridden called getValueIcon(). It is not on the field level but for the entire grid. Just check for the desired column/value and return your desired icon Url or null for no icon. Or go with the cell formatter and return HTML including your image.

              Comment


                #8
                This will work:

                Code:
                import com.smartgwt.client.widgets.Canvas;
                
                public abstract class HtmlUtil {
                
                	private static final String TRUE_IMG = Canvas
                	        .imgHTML("[SKINIMG]/DynamicForm/unchecked.png");
                	private static final String FALSE_IMG = Canvas
                	        .imgHTML("[SKINIMG]/DynamicForm/checked.png");
                
                	// -----------------------------------------------
                
                	public static String getBooleanImg(boolean value) {
                		return value ? TRUE_IMG : FALSE_IMG;
                	}
                
                	public static String getFalseImg() {
                		return FALSE_IMG;
                	}
                
                	public static String getTrueImg() {
                		return TRUE_IMG;
                	}
                }

                Comment

                Working...
                X