Announcement

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

    ListGrid filter box with dropdown list of distinct values

    I need to show a dropdown list of distinct column values in a filter box of a ListGrid.

    My code is based on the Live Filter example. In this example the dropdown for continent list is populated in datasource via
    continentField.setValueMap("Europe", "Asia",...);

    To have this data dynamically sourced from the database, I am using SelectItem with OptionDataSource:

    ListGridField f = new ListGridField(def.name, def.title);
    SelectItem si = new SelectItem(def.name, def.title);
    si.setOptionDataSource(optionDs);
    f.setFilterEditorType(si);

    The option datasource fetch is executed once and populates the dropdown list in the filter.

    How can I force the datasource to do fetch every time the data in the grid has changed?

    Thank you

    #2
    You don't need to do anything, the drop-down will be updated via automatic cache synchronization. See the QuickStart Guide Data Integration chapter for details, and also see the FAQ about grids not updating if you are not seeing automatic updates.

    Comment


      #3
      I cannot make the dropdown list update after the grid updated.

      I use the open source version of Smart GWT and have written GWT RPC based datasources with server-side database implementation.
      The grid and SelectItem use different data sources. The grid uses select from a table, SelectItem uses select distinct column from the same table.

      Thanks

      Comment


        #4
        For a manual refresh, call SelectItem.fetchData().

        Note that the FAQ explains why GWT-RPC is a bad idea in great depth.

        Comment


          #5
          Calling SelectItem.fetchData() gives:

          com.google.gwt.core.client.JavaScriptException: (TypeError) @com.google.gwt.core.client.impl.Impl::apply(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)([JavaScript object(5373), JavaScript object(4935), JavaScript object(5377)]): self.fetchData is not a function

          It looks like the SelectItem control has not been created. I have read on forums that it is just used as a template for ListGridField when this code f.setFilterEditorType(si) is executed.

          I have read about GWT-RPC in FAQ, just need to add functionality to an existing application.

          Comment


            #6
            So - in a nutshell,
            - you have a ListGrid showing a filterEditor,
            - and for some field, the filterEditor formItem is a SelectItem with an optionDataSource
            - and you need to refresh the data within that item.

            Seems like there are a couple of options here:
            1) If you want to just get a pointer to the live SelectItem, you can use the following approach:
            - call "getMember(0)" on the ListGrid to get a pointer to the "FilterEditor" listGrid.
            This will return a Canvas, so use the syntax
            Code:
            ListGrid filterEditor = new ListGrid(<someList>.getMember(0).getJsObj());
            to create a Java ListGrid instance to represent the filter editor ListGrid.
            - use "getEditFormItem(<fieldName>);" to get a pointer to the SelectItem itself, and then call whatever API makes sense for your usage (setOptionCriteria() / fetchData() / invalidateCache(), etc)

            2) If you have a genuine change to the data set backing the optionDataSource, you can have the dataSource notify everything that is bound to it (including this SelectItem) via the "updateCaches" API on DataSource (potentially with "invalidateCache" set to force everything to re-fetch in entirety)

            3) It might be simpler to code this via an entirely different approach: You could simply call "setFields" with a new set of fields including your new ListGridField definition with filterEditorProperties specified. This is likely to be the most inefficient of these approaches so wouldn't be recommended if you are planning to have this refresh happen frequently / repeatedly but would be acceptable for a simple occasional refresh.

            Regards
            Isomorphic Software

            Comment


              #7
              SmartClient Version: v8.3p_2013-04-10/LGPL Development Only (built 2013-04-10)

              I have tried to use option 1)
              ListGrid filterEditor = new ListGrid(grid.getMember(0).getJsObj());
              FormItem editFormItem = filterEditor.getEditFormItem("originator");
              String type = editFormItem.getType();

              It did not work for me as the editFormItem type is "text", not "SelectItem" as you suggested.

              Thank you

              Comment


                #8
                To convert to the correct type, use new SelectItem(editFormItem.getJsObj());

                Comment


                  #9
                  That resolved my problem. Now I can update the grid filter box drop-down list after grid data changed with the following code:

                  ListGrid filterEditor = new ListGrid(grid.getMember(0).getJsObj());
                  FormItem editFormItem = filterEditor.getEditFormItem(def.name);
                  SelectItem si = new SelectItem(editFormItem.getJsObj());
                  si.fetchData();

                  Thank you, Isomorphic, very much for your help!

                  Comment

                  Working...
                  X