Announcement

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

    Recommended approach to augment criteria of a ListGrid FilterEditor

    Hi,

    what is the recommended approach to augment criteria of a ListGrid FilterEditor?
    Scenario:
    A ListGrid and a FilterEditor to filter data; works OK.
    Now, I want to introduce two new SelectItems (above the FilterEditor) showing data from a different DataSource.
    The SelectItems should be used to determine the value of an artificial list grid field used to group the ListGrid.
    This cannot be done on the client, so the current value of the SelectItems needs to be passed to the server.
    I thought about using criteria for this and created two additional SelectItems in a filterForm above the ListGrid.

    Now, what is the most suitable way to incorporate the SelectItems's information into the ListGrid's criteria?
    So far I tried to add a FilterEditorSubmitHandler like this:
    Code:
     
    final SelectItem selector1 = new SelectItem("criteriaField1ID");
    final SelectItem selector2 = new SelectItem("criteriaField2ID");
    ...
    final DynamicForm filterForm = new DynamicForm();  //holds the two selectors
    ...
    filterForm.setFields(startAreaSelector, endAreaSelector);
    ...
    listGridInstance.addFilterEditorSubmitHandler(new FilterEditorSubmitHandler() {
    	@Override
    	public void onFilterEditorSubmit(FilterEditorSubmitEvent event) {
    		if(selector1.getValue() != null && selector2.getValue() != null){  //just incorporate additional critieria if both fields are set
    			Criteria criteriaFromSelectors = filterForm.getValuesAsCriteria();
    			final Criteria filterCriteriaFromGrid = event.getCriteria();
    			filterCriteriaFromGrid.asAdvancedCriteria().addCriteria(criteriaFromAreaSelectors); //needs to call asAdvancedCriteria(), otherwise, there is a JS error
    	}
     };
    This works but accumulates the criteria of the criteriaFromSelectors if the filtering is done multiple times, i.e. event.getCriteria() next time already contains criteriaFromSelectors criteria from previous calls (is there a simple way to get rid of them?).
    I also tried a whole battery of different approches (e.g. combining listGrid.getFilterEditorCriteria() and criteriaFromSelectors into a new criteria object and then doing a fetch(combinedCriteria)) but so far, each of them had at least one flaw. Before getting deeper into this, I'd like to know whether I have overlooked something obvious...

    Thanks
    fatzopilot

    #2
    This is similar to what you can see in the Dynamic Reporting sample - take a look.

    Comment


      #3
      Thanks, that example helped breaking down the issue :)

      Comment


        #4
        Thanks, helped me as well.
        Showcase URL is http://www.smartclient.com/smartgwte...amic_reporting.

        I want to add that if you get your data with ListGrid.fetch(new Criterion("MYFIELD", OperatorId.NOT_NULL)) this Criteria does not stay when you enter stuff in the filter row.

        Instead use:
        Code:
        critArray = new Criterion[] { new Criterion("MYFIELD", OperatorId.NOT_NULL) };
        advCompanyCrit = new AdvancedCriteria(OperatorId.AND, critArray);
        fetchData(advCompanyCrit);
        Best regards,
        Blama

        Comment

        Working...
        X