Announcement

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

    Sorting v Filtering

    I have a ListGrid with a client-only DataSource where I need to display numeric data in a textual format, i.e. I wish to display "10 GB" or "200 KB", not their numeric equivalents. However, I wish to sort the records based on the numeric equivalents (i.e. in an increasing order sort, I want "200 KB" to come before "10 GB"). Using a CellFormatter, I am able to do this.

    However, I would like to be able to filter based on the textual representation that the user sees, rather than the numeric values (i.e. type "MB" and get all the records the have megabyte range values). Is that possible with a SmartGWT ListGrid?

    Thank you,
    Greg
    Last edited by Greg D; 13 Aug 2014, 08:55.

    #2
    If instead of doing the formatting on the fly, you configure a displayField that has the formatted value, filtering will go against the displayField.

    However if you are using the default mixture of both client and server filtering, bear in mind your server logic will receive criteria that target the displayField and will have to handle it.

    Comment


      #3
      Thank you for the response.

      All the sorting and filtering is Client side. I'm looking at 600 records max, and no paging.

      If I "configure a displayField that has the formatted value", what happens with sorting?

      Comment


        #4
        It also uses the displayValue.

        Comment


          #5
          Ah, well that would leave me with "10 GB" coming before "200 KB" in an increasing order sort. And my first priority is that when I sort on that column, "10 GB" is bigger than "200 KB".

          I think that basically what I'm looking for is to have a Client side "custom filter" hook, kind of like having the CellFormatter hook. I take it you don't have that, so please consider this a feature request.

          Thank you for your time,

          Comment


            #6
            We actually do have such APIs, there's two approaches:

            1. you could customize the listGridField.filterEditorType with a FormItem that overrides getCriterion(). Note your Criterion is going to be applied to the underlying (integer) value so your logic may be tricky here, eg for input of "10" you might return an iContains Criterion, but for "K" or "KB" you might return a greaterThan and lessThan criteria to select values that are in the right range. Or, you could come up with a custom FormItem that allows separately choosing quantity + units to avoid these ambiguities.

            2. there is a documented and supported SmartClient API for customizing filtering, which is not yet available in SmartGWT, but still usable via JSNI:

            http://www.smartclient.com/docs/release/a/b/c/go.html#method..ResultSet.applyFilter

            Comment


              #7
              Thank you, I'll look into that.

              Comment


                #8
                I tried that, and the filter field was filled with the contents of the Constraint, rather than the text the user typed.

                Someone on StackOverflow pointed me to the ListGridRecord.setSortNormalizer (). This is letting me return a Long for the sort, and filter on the text, which gives me what I wanted.

                Comment


                  #9
                  We'd not sure what you mean about the "contents of the Constraint", but just for others: #1 is a known-working approach that the framework itself uses routinely.

                  Comment


                    #10
                    in my override of getCriterion, if the user typed "G" and I returned
                    Code:
                    	String	theValue = item.getValue ().toString ();
                    	OperatorId	operator = OperatorId.AND;
                    
                    	return new Criterion (fieldName, operator, theValue);
                    The place where the user typed "G" would display the text " and G"

                    Comment


                      #11
                      That kind of thing could happen if you didn't also implement a setCriterion() behavior - see the Criteria Editing overview.

                      Comment

                      Working...
                      X