Announcement

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

    HowTo: SelectItem without cache, refreshed on picklist open

    Hi Isomorphic,

    this has been asked a lot in the forum, but there never was an answer, apart from "use fetchData()". But the question is when and how to execute this.
    So my question is: How does one create a SelectItem that always reloads its data when the picklist is shown. In my language that would be a "SelectItem without cache".

    SelectItem.setCachePickListResults() - which seems to be right from the docs - does not do the trick.

    This here:
    Code:
    addPickerIconClickHandler(new PickerIconClickHandler() {
                    @Override
                    public void onPickerIconClick(PickerIconClickEvent event) {
                        ((SelectItem) event.getFiringItem()).fetchData();
                    }
                });
    works, but only on click on the tiny arrow. But the pickList is also shown on click in the left "text area" of the SelectItem, and this much more common click does not trigger the reload.

    I know that you could use ResultSet-cacheUpdates, but this is not always the right thing and requires code. A "dumb" SelectItem would be better here.

    Perhaps a "showPickListHandler" would be useful? Or is there another way?

    Thank you & Best regards
    Blama

    #2
    Install a pickListCriteria function that always changes the criteria (by passing along the current timestamp, for example).

    This also allows you to make it slightly less often than every time if you need to - by for example only passing a cache-breaking "timestamp" value in the criteria if at least 5 seconds have passed.

    Comment


      #3
      Hi Isomorphic,

      thanks for the fast answer. Unfortunately this does not work for me. I created a testcase that is very close to my usecase here.
      My problems are:
      • The criteria do not change on re-open via the pickerIcon (what you suggested as solution, how can I get them to be dynamic without setting them myself again?)
      • There is no fetch on re-open of the SelectItem via click in the non-pickerIcon area
      Could you have a look?

      Code:
      isc.DynamicForm.create(
      {
          ID: "myForm",
          width: 500,
          fields: [
          {
              name: "aggSelect",
              title: "Item Name",
              editorType: "SelectItem",
              multiple: true,
              optionDataSource: "filteredAggregation_orderItem",
              optionOperationId: "summary",
              pickListWidth: 250,
              sortField: "itemName",
              valueField: "itemName",
              displayField: "itemName",
              pickListCriteria:
              {
                  _constructor: "AdvancedCriteria",
                  operator: "and",
                  criteria: [
                  {
                      fieldName: "itemName",
                      operator: "lessThan",
                      value: "H"
                  },
                  {
                      fieldName: "itemName",
                      operator: "notEqual",
                      value: new Date().toJSON()
                  }]
              },
              pickListFields: [
                  { name: "itemName" },
                  { name: "quantity", title: "Total qty" }
              ],
              pickerIconClick: function(form, item, pickerIcon) { item.fetchData(); }
          }]
      });
      // In my usecase this list shows unaggregated data and I want the SelectItem count-column to update on delete in this base data table.
      // Here the ResultSet-cacheupdate on delete removes the row in the SelectItem, but in my case the number should be one less.
      isc.ListGrid.create(
      {
          ID: "orderItemSummaryList",
          width: 800,
          height: 400,
          alternateRecordStyles: true,
          autoFetchData: true,
          canRemoveRecords: true,
          dataSource: filteredAggregation_orderItem,
          initialCriteria:
          {
              _constructor: "AdvancedCriteria",
              operator: "and",
              criteria: [
              {
                  fieldName: "itemName",
                  operator: "lessThan",
                  value: "H"
              }, ]
          },
          dataFetchMode: "basic",
          showAllRecords: true,
          sortField: "itemName",
          fetchOperation: "fetch",
          fields: [
              { name: "itemName", width: 400 },
              { name: "SKU" },
              { name: "unitCost" },
              { name: "quantity", title: "Total qty" },
              { name: "totalSales", width: 100 }
          ]
      });
      isc.VLayout.create(
      {
          membersMargin: 20,
          members: [myForm, orderItemSummaryList]
      });
      Thank you & Best regards
      Blama

      Comment


        #4
        You haven't installed a pickListCriteriaFunction (SmartGWT terminology) or getPickListCriteria override (SmartClient terminology). You've just specified static pickListCriteria - those don't change, because you don't have a function.

        Comment


          #5
          Hi Isomorphic,

          thanks, this is working as expected with this code and no pickerIconClick or pickListCriteria.

          Code:
          getPickListFilterCriteria: function() {
                      return {
                          _constructor: "AdvancedCriteria",
                          operator: "and",
                          criteria: [{
                                  fieldName: "itemName",
                                  operator: "lessThan",
                                  value: "H"
                              },
                              {
                                  fieldName: "itemName",
                                  operator: "notEqual",
                                  value: new Date().toJSON()
                              }
                          ]
                      }
                  },
          For every open of the pickList I do see a new request in the RPC Tab.

          Best regards
          Blama

          Comment

          Working...
          X