Announcement

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

    Persistent filter editor on ListGrid

    Hi,

    I would like to use the persistence framework (Offline) to store the user specific filter selection of a ListGrid and restore it at next grid construction.

    However the state string on a ListGrid, while containing a lot of stuff (selection, columns layout, sort, hilites, ...), does not seem to store any information relative to the filter criteria.

    Is there any way to get the FilterEditor state stored ?

    Thanks, Ben.

    #2
    someCriteria.getValues() will return the Criteria as a Map object.

    You can store this in Offline by using something like:
    Code:
    Offline.put("myGridPrefs", someCriteria.getValues());
    Not sure if Criteria has a convenience method for adding Criteria to it from a map but it would be easy enough to create one.

    I'm assuming you know how to get the Criteria to / from the FilterEditor in the ListGrid.

    Comment


      #3
      Haven't tried any of these, but you might be able to serialize / deserialize the Criteria as JSON / XML and store it in a DB.

      Comment


        #4
        Thanks, will try.

        Comment


          #5
          Thanks for the advice. However I cannot find any convenience method to rebuild the Criteria based on its .toString representation or any serialization. And it is not easy at all to rebuild it myself since with complex criteria the Map can have several levels of recursion with many different attributes that would be impossible for me to anticipate in a comprehensive way. Here is an example of the a .toString on the Map of Criteria with 3 filtered fields of different types:

          Code:
          {statusIs_final=false, operator=and, criteria=[{_constructor=AdvancedCriteria, operator=and, criteria=[{fieldName=statusDate_due, operator=greaterOrEqual, value={_constructor=RelativeDate, value=+3d[-0D], rangePosition=start}}, {fieldName=statusDate_due, operator=lessOrEqual, value={_constructor=RelativeDate, value=+4m[+0D], rangePosition=end}}]}, {fieldName=name, operator=iContains, value=45}]}
          As you see parsing this in a generic way is not that easy, first because the full syntax (names of all possible operators, _construtors, values for some criteria types like Date +4m[+0D] ...) has to be known (I don't thing this is documented) and second many levels of nesting have to be isolated.

          Even if I develop this miracle parsing, I will never have the guarantee that it will remain robust with new versions.

          So my question to SGWT remains: Is there a way to instantiate a Criteria with an arbitrary complexity from its .toString or any other string representation that could be stored in a Cookie ? Or any way to store and restore filter state ?

          Thanks, Ben.
          Last edited by bda@n-side.com; 5 Jan 2013, 12:59.

          Comment


            #6
            Criteria is JsObject so you may use criteria.getJsObj() and then serialize it by JSON.encode() and store.
            Recreating can be done opposite way and finally using constructor new Criteria(jsObject)
            MichalG

            Comment


              #7
              Many thanks michalg !

              Comment

              Working...
              X