Announcement

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

    ListGrid: group date by week

    1. latest nightly build smartgwt power edition (16/04/2013)
    2. FireFox 20.0.1

    If one uses the 'Group by Week' option on a date column in a ListGrid, currently the first day of a week depends on the first day of the specific year. Could it not be possible to use the locale to determine the start of a week?
    For instance Monday for locale nl, fr, en_GB and Sunday for locale en_US.

    The lower example shows when the listgrid is grouped by cntn_date on week, that the current week group 'Week #16' contains date Tuesday 16/04/2013 till Monday 22/04/2013 instead of Monday 15/04/2013 till Sunday 21/04/2013
    (cntn_week shows the desired week).

    Code example:
    Code:
    package test.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class Test implements EntryPoint {
    
    	private VLayout vlayout = new VLayout();
    	private ListGrid listGrid = new ListGrid();
    
    	/**
    	 * This is the entry point method.
    	 */
    	
    	public void onModuleLoad() {
    		vlayout.setWidth100();
    		vlayout.setHeight100();
    
    		listGrid.setDataSource(ContentDS.getInstance());
    		listGrid.setAutoFetchData(true);
    		
    		vlayout.addMember(listGrid);
    		vlayout.draw();
    	}
    }
    Datasource example:
    Code:
    package test.client;
    
    import java.util.Date;
    
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.Record;
    import com.smartgwt.client.data.fields.DataSourceDateField;
    import com.smartgwt.client.data.fields.DataSourceIntegerField;
    
    public class ContentDS extends DataSource {
    
    	private static ContentDS instance = null;
    
    	public static ContentDS getInstance() {
    		if (instance == null) {
    			instance = new ContentDS("contentDS");
    		}
    		return instance;
    	}
    
    	private ContentDS(String id) {
    		setID(id);
    		setClientOnly(true);
    
    		DataSourceIntegerField pkField = new DataSourceIntegerField("cntn_pk");  
            pkField.setHidden(true);  
            pkField.setPrimaryKey(true);
    		
            DataSourceIntegerField weekField = new DataSourceIntegerField("cntn_week");
            
    		DataSourceDateField dateField = new DataSourceDateField("cntn_date");
    
    		setFields(pkField, weekField, dateField);
    		
    		setTestData(
    				new ContentRecord(1, 15, new Date(2013-1900, 3, 14)),
    				new ContentRecord(2, 16, new Date(2013-1900, 3, 15)),
    				new ContentRecord(3, 16, new Date(2013-1900, 3, 16)),
    				new ContentRecord(4, 16, new Date(2013-1900, 3, 17)),
    				new ContentRecord(5, 16, new Date(2013-1900, 3, 18)),
    				new ContentRecord(6, 16, new Date(2013-1900, 3, 19)),
    				new ContentRecord(7, 16, new Date(2013-1900, 3, 20)),
    				new ContentRecord(8, 16, new Date(2013-1900, 3, 21)),
    				new ContentRecord(9, 17, new Date(2013-1900, 3, 22)),
    				new ContentRecord(10, 17, new Date(2013-1900, 3, 23)));
    	}
    
    	private class ContentRecord extends Record {
    		public ContentRecord(Integer pk, Integer week, Date date) {
    			setAttribute("cntn_pk", pk);
    			setAttribute("cntn_week", week);
    			setAttribute("cntn_date", date);
    		}		
    	}
    }
    Last edited by daviddb; 16 Apr 2013, 02:53. Reason: explaining example more clearly

    #2
    Thanks for pointing this out, it's been fixed for tomorrow's 3.1 and 4.0 builds.

    Comment

    Working...
    X