Announcement

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

    Unable to get ListGrid filtering to work with client only datasource

    Browser: Firefox 3.6.6
    SmartClient version: Isomorphic SmartClient Framework (SC_SNAPSHOT-2010-10-03/EVAL Deployment 2010-10-03)

    I'm attempting to use the Filter Editor capabilities of the ListGrid for a Client Only datasource. Everything looks good until you actually try to filter. The result is that all entries go away, regardless of what you attempt to filter by.

    The Datasource:
    Code:
    public class AvailableActivitiesDS extends DataSource {
    
    	public AvailableActivitiesDS() {
    
    		DataSourceIntegerField id = new DataSourceIntegerField("id", "Activity ID");
    		addField(id);
    		id.setPrimaryKey(true);
    		id.setHidden(true);
    
    		DataSourceTextField name = new DataSourceTextField("name", "Activity", 125);
    		addField(name);
    
    		DataSourceTextField description = new DataSourceTextField("description", "Description", 200);
    		addField(description);
    
    		setClientOnly(true);
    	}
    }
    The grid:
    Code:
    myAvailableActivitiesGrid = new ListGrid();
    myAvailableActivitiesGrid.setDataSource(getAvailableActivitiesDs());
    ListGridField[] fields = myAvailableActivitiesGrid.getFields();
    for (ListGridField field: fields) {
    	field.setFilterOperator(OperatorId.ICONTAINS);
    }
    myAvailableActivitiesGrid.setAlternateRecordStyles(true);
    myAvailableActivitiesGrid.setHeight100();
    myAvailableActivitiesGrid.setShowResizeBar(false);
    myAvailableActivitiesGrid.setCanAcceptDroppedRecords(true);
    myAvailableActivitiesGrid.setCanDragRecordsOut(true);
    myAvailableActivitiesGrid.setShowFilterEditor(true);
    myAvailableActivitiesGrid.setDataFetchMode(FetchMode.LOCAL);
    myAvailableActivitiesGrid.addDropHandler(new DropHandler() {
    	@Override
    	public void onDrop(DropEvent event) {
    		removeActivities(getSelectedActivitiesGrid().getSelection());
    	}
    });
    Loading the grid:
    Code:
    RecordList availableActivityRecords = new RecordList();
    
    for (Record activity: activities) {
    	availableActivityRecords.add(activity);
    }
    
    ResultSet resultSet = new ResultSet(getAvailableActivitiesDs());
    resultSet.setAllRows(availableActivityRecords.toArray());
    resultSet.setUseClientFiltering(true);
    myAvailableActivitiesGrid.setData(resultSet);
    Thanks.

    #2
    Your DataSource has no data, so all results are empty.

    Provide the data to the DataSource (setCacheData()) not the grid.

    Comment


      #3
      I've changed it and am now getting the following error. I guess this brings up the question of when are you supposed to call setCacheData()? Also, are you allowed to call it multiple times? For me, this list grid is meant to be fluid. Is this telling me that the underlying data source cannot be changed? By the way, in this case, this is the first time I've called setCacheData() on the datasource. Also, the call was done after it was attached to the ListGrid.

      Code:
      java.lang.IllegalStateException: Cannot change configuration property 'cacheData' to [Lcom.smartgwt.client.data.Record;@45ef08 after the component has been created.
          at com.smartgwt.client.core.BaseClass.error(BaseClass.java:144)
          at com.smartgwt.client.core.BaseClass.error(BaseClass.java:131)
          at com.smartgwt.client.core.BaseClass.setAttribute(BaseClass.java:355)
          at com.smartgwt.client.data.DataSource.setCacheData(DataSource.java:270)
          at com.islandpacific.gui.client.RoleActivities$9.execute(RoleActivities.java:437)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
          at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
          at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
          at com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:1713)
          at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:165)
          at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120)
          at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507)
          at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264)
          at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
          at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
          at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188)
          at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
          at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
          at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
          at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
          at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
          at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
          at java.lang.Thread.run(Unknown Source)

      Comment


        #4
        You're allowed to call it multiple times, in fact, this was just corrected 2 days ago. However, you don't need to grab a new build - you should be providing the cache data to the DataSource *before* you attach it to the ListGrid, that's what makes sense from a lifecycle perspective (otherwise, the grid might fetch while the DataSource is empty, depending on your settings).

        Comment


          #5
          It doesn't seem to want to be called multiple times. I'm still stuck with the error, regardless of when I initialize the cache.

          If it is OK to call multiple times, why would the following be in the javadoc for Datasource.setCacheData()?

          Throws:
          IllegalStateException - this property cannot be changed after the underlying component has been created

          What exactly was fixed 2 days ago? Maybe I need that.

          Comment


            #6
            Where are you looking at the javadocs? The latest build does not have this and you can call DataSource.setCacheData(..) without the error.

            Sanjiv

            Comment


              #7
              I'm looking at the javadoc on the smartclient.com web site:

              http://www.smartclient.com/smartgwt/javadoc/

              Comment

              Working...
              X