Announcement

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

    Not able to get Daterange on listgrid filter editor

    Hi,

    I am struggling to display listgrid filter editor with date range. In my older smartgwt version 2.2 on list grid Date/DateTime fields it was showing data range editor but after upgrading to smartgwt 4.0d (build from daily build 01/01/2014) it is showing date picker instead of date range popup. I gone through lot of posts and came across the information, if i set DataSource setWillHandleAdvancedCriteria to true it will show date range popup but i am not able to find this method at all in DataSource class, am i missing something...? How to get the date range filter popup for listgrid date/datetime column filters..? Any help is highly appreciated.

    Thanks a lot in advance

    #2
    Showing a range picker (actually, its a MiniDateRangeItem) is automatic behavior - if that's not happening, you must have settings causing the difference.

    Please show a minimal test case we can run to see the issue.
    Last edited by Isomorphic; 4 Jan 2014, 23:03.

    Comment


      #3
      Here is the example/use case i have created, the same example in previous version of smartgwt 2.2 was showing minidaterange for date fields but after upgrading it to 4.0d (01/01/2014 nightly build) it is showing date picker instead of minidaterange. I tested it in IE 9.0, Chrome and FF, got same behavior. Please advice.

      Code:
      package com.test.client;
      
      import java.util.ArrayList;
      import com.google.gwt.core.client.EntryPoint;
      import com.google.gwt.user.client.ui.RootLayoutPanel;
      import com.smartgwt.client.data.DataSource;
      import com.smartgwt.client.data.DataSourceField;
      import com.smartgwt.client.data.fields.DataSourceIntegerField;
      import com.smartgwt.client.types.DSDataFormat;
      import com.smartgwt.client.types.DSProtocol;
      import com.smartgwt.client.types.FieldType;
      import com.smartgwt.client.widgets.grid.ListGrid;
      import com.smartgwt.client.widgets.grid.ListGridField;
      import com.smartgwt.client.widgets.layout.HLayout;
      import com.smartgwt.client.widgets.layout.VLayout;
      
      public class Test implements EntryPoint
      {
      
      	private static final class ShowcaseConstants
      	{
      		static final String PRIMARY_KEY = "primaryKey";
      		static final String FORECAST_START = "forecastStart";
      		static final String TASK_RTID = "taskRtid";
      		static final String TASK_STATUS = "taskStatus";
      		static final String CHANGE_ME = "changeMe";
      	}
      
      	private ListGrid listGrid;
      	private FilterDS filterDs;
      	private VLayout mainLayout;
      
      	public void onModuleLoad()
      	{
      
      		// main layout occupies the whole area
      		mainLayout = new VLayout();
      		mainLayout.setWidth100();
      		mainLayout.setHeight100();
      
      		mainLayout.addMember(new ListGridLayout());
      		RootLayoutPanel.get().add(mainLayout);
      
      	}
      
      	private static class FilterDS extends DataSource
      	{
      		private static FilterDS instance = null;
      
      		public static FilterDS getInstance()
      		{
      			if (instance == null)
      			{
      				instance = new FilterDS("filterTestDS");
      			}
      			return instance;
      		}
      
      		private final DataSourceField primaryKey;
      
      		public FilterDS(String id)
      		{
      			setDataProtocol(DSProtocol.CLIENTCUSTOM);
      			setDataFormat(DSDataFormat.CUSTOM);
      			setID(id);
      			primaryKey = new DataSourceIntegerField(ShowcaseConstants.PRIMARY_KEY);
      			primaryKey.setHidden(true);
      			primaryKey.setPrimaryKey(true);
      			DataSourceField taskRtid = new DataSourceField(ShowcaseConstants.TASK_RTID, FieldType.TEXT, "Task");
      			DataSourceField taskStatus = new DataSourceField(ShowcaseConstants.TASK_STATUS, FieldType.TEXT, "TaskStatus");
      			DataSourceField forecastStart = new DataSourceField(ShowcaseConstants.FORECAST_START, FieldType.DATE, "Forcefs");
      			DataSourceField changeMe = new DataSourceField(ShowcaseConstants.CHANGE_ME, FieldType.TEXT, "ChangeME");
      			setClientOnly(true);
      			setFields(primaryKey, taskRtid, taskStatus, forecastStart, changeMe);
      		}
      
      	}
      
      	private class ListGridLayout extends HLayout
      	{
      
      		public ListGridLayout()
      		{
      			listGrid = new ListGrid();
      			listGrid.setWidth100();
      			listGrid.setHeight100();
      			listGrid.setShowFilterEditor(true);
      
      			filterDs = FilterDS.getInstance();
      			ArrayList<ListGridField> fields = new ArrayList<ListGridField>();
      			for (DataSourceField s : filterDs.getFields())
      			{
      				ListGridField ff = new ListGridField(s.getJsObj());
      				fields.add(ff);
      			}
      			listGrid.setFields(fields.toArray(new ListGridField[fields.size()]));
      
      			this.addMember(listGrid);
      		}
      
      	}
      }

      Comment


        #4
        You need to call DataSourceField.setType("date") or "datetime".

        Also, the loop that adds the fields to your listGrid is unneccessary, as it stands. That code doesn't seem to be doing anything except directly copying the DS fields, so you can just get rid of that code and set ListGrid.setUseAllDataSourceFields(true) instead.
        Last edited by Isomorphic; 5 Jan 2014, 22:16.

        Comment


          #5
          Actually, on looking a bit deeper, we see that the issue you're having won't be fixed by the advice in our last post.

          The problem is caused by your code that manually create a list of ListGridFields from a list of DataSourceFields. Why are you doing that?

          The correct way to do this is to get rid of that code and, instead, just call listGrid.setDataSource(filterDs).

          Comment


            #6
            While creating the listgrid fields we are placing lot of other properties like setAlign, setWidth, setCanSortClientOnly, setCanSort, setCellFormatter etc some of these properties are not available in DataSourceField so can not skip this step. I tried a workaround to explicitly set FilterEditorProperties to MiniDateRange if the data type is DATE/DATETIME then it started showing me the date range. For now i can leave with this

            Code:
            listGridField.setFilterEditorProperties(new MiniDateRangeItem());
            Thanks for quick response.

            Comment

            Working...
            X