Announcement

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

    ListGrid header field is not being centered

    Hi,

    SC_SNAPSHOT-2011-03-24/EVAL Deployment
    FireFox 3.6.16

    The header fields of the listgrid are not correctly aligned when using
    setAlign(Alignment.CENTER). The cell values are.

    Standalone test case added.

    Originally posted by javadoc
    void com.smartgwt.client.widgets.grid.ListGridField.setAlign(Alignment align)

    Horizontal alignment for field's column header: "left", "right" or "center".
    Applied to the column header title and cells by default.

    A separate alignment for cells can be specified via cellAlign.
    If null, values are left-aligned. If this field is editable, the alignment of cells in the body will also be reflected in any editors for the field.

    Parameters:
    align align Default value is null
    Code:
    public class Standalone implements EntryPoint {
    		
    	private static Canvas masterPanel = null;
    
    	public void onModuleLoad() {
    		   		
    		//masterPanel should be a Layout
    		masterPanel = new Canvas(); 
    		masterPanel.setHeight100();
    		masterPanel.setWidth100();
    		masterPanel.setStyleName("pageBackground"); //background style from skin
    		
    		masterPanel.addChild(testCase10());
    		masterPanel.draw();	
    	}
    
    
       public ListGrid testCase4() {   
      	  
            DataSource dataSource = new DataSource();   
      
            DataSourceField myTextField = new DataSourceField();   
            myTextField.setName("textField");   
            myTextField.setTitle("textField");   
     
            dataSource.setFields(myTextField);   
            
            ListGridRecord[] result = new ListGridRecord[1];
            result[0] = new ListGridRecord();
            result[0].setAttribute("textField", "test input");
               
            //the order list grid   
            ListGrid ordersList = new ListGrid();   
            ordersList.setHeight(170);   
            ordersList.setWidth(500);
            ordersList.setCanEdit(true);
            ordersList.setDataSource(dataSource);
            ordersList.setData(result);
            ordersList.setVisible(false);
            ordersList.draw();
            
            ListGridField[] fields = ordersList.getAllFields();
            for(int i=0; i < fields.length; i++){
            	fields[i].setAlign(Alignment.CENTER);
            }
            ordersList.markForRedraw();
            ordersList.show();
       
    		return ordersList;
        }
    
    }

    #2
    Looks like the issue here is actually that you're setting the alignment on the fields after they've been assigned to the grid and we don't automatically detect subsequent changes to the field and rebuild the associated column header button.
    If you assign explicit ListGridFields to your grid via setFields() with alignment specified the alignment will effect both.

    Alternatively if you delay the draw until after running your code, or force a refresh via a call to setFields() or a setShowHeader(false); setShowHeader(true) cycle you should see the header button updated in the live grid.

    Comment


      #3
      The only way I was able to get the desired behavior (using SmartGWT v2.5) was by manually adding fields to the ListGrid, where I had to setAlign() on the entire column, then call setCellAlign() immediately afterwards. Here's a terse code snippet, where the mfgOrderId field is a numeric type:

      Code:
      ListGrid listGrid = new ListGrid();
      ListGridField field1 = new ListGridField("mfgOrderId", "Mfg. Order ID");
      
      // causes left align of entire column, header label and all.
      field1.setAlign(Alignment.LEFT);
      // realigns non-header cell contents back to the right.
      field1.setCellAlign(Alignment.RIGHT);
      
      listGrid.setFields(field1);

      Comment

      Working...
      X