Announcement

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

    filterBuilder

    Hi All,

    I am user a filterBuilder to allow users to subset data in a table. At some point, the user performs an analysis (SQC, Pareto, Histogram, etc.) Each of these analyzes define buckets of data that can be used to subset the data further. What I did in the past was update the SQL where clause with the additional constraints. Now that I am using filterBuilder, I think I need to update the advanced criteria in the filterBuilder. This involves adding a top level "AND".

    So, what I essentially need to do is programatically update the advanced criteria in the filterBuilder. Is this possible?

    Cheers,
    Arend

    #2
    Hi All,

    I have a followup question. I sometimes use RequestBuilder to send a request to my server. To do this I need to get the operator and the list of criteria from the AdvancedCriteria. Should I do this using getAttribute?

    Thanks,
    Arend

    Comment


      #3
      Hi All,

      I have broken down some of the attributes returned as part of an advanced criteria. I can return the criteria as a java script object:

      Code:
      com.google.gwt.core.client.JavaScriptObject lcriteria = criteria.getAttributeAsJavaScriptObject("criteria");
      I now want to try accessing a few of these objects member functions. Where would I find documentation describing its interface?

      Thanks,
      Arend

      Comment


        #4
        Hi!

        Currently there is an open issue regarding AdvancedCriteria, see http://code.google.com/p/smartgwt/issues/detail?id=93.
        You can star it to get notified of changes.

        Greetz

        Comment


          #5
          The SmartClient Reference for 7.0 beta has a chapter on the JavaScript structure of the AdvancedCriteria object. Here it is for your convenience - there's a bunch more doc available if you download the beta from the Isomorphic blog.

          AdvancedCriteria is a format for representing search criteria which may include operators on field values such as "less than", or may include sub-clauses such as several criteria applied to fields joined by an "OR" operator.

          SmartClient DataSources can use AdvancedCriteria to search a list of Records, and the SmartClient Java Server can translate AdvancedCriteria to SQL queries. If the entire dataset is cached locally, SmartClient can perform AdvancedCriteria filtering on the client, avoiding a server call.

          An AdvancedCriteria is an ordinary JavaScript object which can be created directly with JavaScript literal notation. For example:

          Code:
           var advancedCriteria = {
                  _constructor:"AdvancedCriteria",
                  operator:"and",
                  criteria:[
                      // this is a Criterion
                      { fieldName:"salary", operator:"lessThan", value:"80000" },
                      { operator:"or", criteria:[
                            { fieldName:"title", operator:"iContains", value:"Manager" },
                            { fieldName:"reports", operator:"notNull" }
                        ]  
                      }
                  ]
              }
          An AdvancedCriteria is in effect a Criterion that has been marked with _constructor:"AdvancedCriteria" to mark it as complete criteria.

          When passed to the SmartClient Server, AdvancedCriteria are automatically translated to Java Objects, identically to other JavaScript data, by the rules given under RPCRequest.data.

          Other servers may receive AdvancedCriteria in the most convenient format, for example, a DataSource.transformRequest() might translate AdvancedCriteria directly into a SQL-like language, or serialize to XML using DataSource.xmlSerialize().

          Comment


            #6
            Hi,

            Thanks for the information. I would like to take the criterial from an AdvancedCriteria object convert it into a string and send it off to my restful service. For example, I want to send the following as part of my get or post:

            Code:
            {"fieldName":"told-to-dist-act", "operator":"equals", "value":"0.4"},{"fieldName":"aoa-1", "operator":"equals", "value":"0.6"}]
            I think the best way to do this is to get the string representation of a JSON object. The restful service would then be able parse my request build the query and return the correct data. I already do this with a RestfulDataSource on the server. I need to this also as part of a RequestBuilder.

            I have attempted to look at the object in two different ways. The first approach is as follows:

            Code:
            AdvancedCriteria criteria = filterBuilder.getCriteria();
            GWT.log(new JSONObject(criteria.getJsObj()).toString(),null);
            This produced the following log message:

            Code:
            {"_constructor":"AdvancedCriteria", "operator":"and", "criteria":[{"fieldName":"told-to-dist-act", "operator":"equals", "value":"0.4"},{"fieldName":"aoa-1", "operator":"equals", "value":"0.6"}]}
            This makes sense to me and is what the previous poster had indicated. However, I just want the criteria part. So I tried the following:

            Code:
            						
            AdvancedCriteria criteria = filterBuilder.getCriteria();
            JavaScriptObject y = criteria.getAttributeAsJavaScriptObject("criteria");
            GWT.log(new JSONObject(y).toString(),null);
            I would have expected to just get the criteria. Instead I got the following:

            Code:
            {"0":{"fieldName":"told-to-dist-act", "operator":"equals", "value":"0.4"}, "1":{"fieldName":"aoa-1", "operator":"equals", "value":"0.6"}, "Class":"Array", "newInstance":{"_1":null, "$k":1, "Class":"Function"}, "create":{"_1":null, "$k":1, "Class":"Function"}, "observe":{"_1":null, "_2":null, "_3":null, "_4":null, "_5":null, "_6":null, "_7":null, "_8":null, "i":null, "_10":null, "_11":null, "_12":null, "$k":1, "Class":"Function"}, "ignore":{"_1":null, "_2":null, "_3":null, "_4":null, "_5":null, "_6":null, "i":null, "_8":null, "$k":1, "Class":"Function"}, "$dk":{"_1":null, "_2":null, "_3":null, "i":null, "_5":null, "_6":null, "$k":1, "Class":"Function"}, "getPrototype":{"$k":1, "Class":"Function"}, "get":{"_1":null, "$k":1, "Class":"Function"}, "getLength":{"$k":1, "Class":"Function"}, "isEmpty":{"$k":1, "Class":"Function"}, "first":{"$k":1, "Class":"Function"}, "last":{"$k":1, "Class":"Function"}, "indexOf":{"_1":null, "_2":null, "_3":null, "i":null, "$k":1, "Class":"Function"}, "lastIndexOf":{"_1":null, "_2":null, "_3":null, "i":null, "$k":1, "Class":"Function"}, "contains":{"_1":null, "_2":null, "$k":1, "Class":"Function"}, "containsAll":{"_1":null, "_2":null, "i":null, "$k":1, "Class":"Function"}, "intersect":{"_1":null, "i":null, "_3":null, "_4":null, "a":null, "$k":1, "Class":"Function"}, "equals":{"_1":null, "_2":null, "i":null, "$k":1, "Class":"Function"}, "getItems":{"_1":null, "_2":null, "_3":null, "i":null, "$k":1, "Class":"Function"}, "getRange":{"_1":null, "_2":null, "$k":1, "Class":"Function"}, "duplicate":{"$k":1, "Class":"Function"}, "set":{"_1":null, "_2":null, "$k":1, "Class":"Function"}, "addAt":{"_1":null, "_2":null, "i":null, "$k":1, "Class":"Function"}, "removeAt":{"_1":null, "_2":null, "_3":null, "$k":1, "Class":"Function"}, "add":{"_1":null, "_2":null, "_3":null, "_4":null, "$k":1, "Class":"Function"}, "addList":{"_1":null, "_2":null, "_3":null, "_4":null, "$k":1, "Class":"Function"}, "setLength":{"_1":null, "$k":1, "Class":"Function"}, "addListAt":{"_1":null, "_2":null, "i":null, "l":null, "$k":1, "Class":"Function"}, "remove":{"_1":null, "_2":null, "i":null, "$k":1, "Class":"Function"}, "removeList":{"_1":null, "_2":null, "i":null, "l":null, "$k":1, "Class":"Function"}, "removeEvery":{"_1":null, "$k":1, "Class":"Function"}, "dataChanged":{"$k":1, "Class":"Function"}, "$ed":{"_1":null, "$k":1, "Class":"Function"}, "$ee":{"$k":1, "Class":"Function"}, "$52z":{"$k":1, "Class":"Function"}, "setArray":{"_1":null, "i":null, "$k":1, "Class":"Function"}, "addAsList":{"_1":null, "$k":1, "Class":"Function"}, "removeRange":{"_1":null, "_2":null, "_3":null, "$k":1, "Class":"Function"}, "removeWhere":{"_1":null, "_2":null, "i":null, "_4":null, "$k":1, "Class":"Function"}, "removeEmpty":{"_1":null, "_2":null, "i":null, "_4":null, "$k":1, "Class":"Function"}, "getProperty":{"_1":null, "_2":null, "i":null, "l":null, "$k":1, "Class":"Function"}, "getValueMap":{"_1":null, "_2":null, "_3":null, "i":null, "l":null, "_6":null, "$k":1, "Class":"Function"}, "map":{"_1":null, "_2":null, "_3":null, "_4":null, "_5":null, "_6":null, "_7":null, "_8":null, "_9":null, "i":null, "_11":null, "$k":1, "Class":"Function"}, "setProperty":{"_1":null, "_2":null, "i":null, "l":null, "$k":1, "Class":"Function"}, "clearProperty":{"_1":null, "_2":null, "_3":null, "i":null, "l":null, "$k":1, "Class":"Function"}, "getProperties":{"_1":null, "$k":1, "Class":"Function"}, "getUniqueItems":{"_1":null, "i":null, "l":null, "$k":1, "Class":"Function"}, "findIndex":{"_1":null, "_2":null, "$k":1, "Class":"Function"}, "findNextIndex":{"_1":null, "_2":null, "_3":null, "_4":null, "i":null, "$k":1, "Class":"Function"}, "findNextMatch":{"_1":null, "_2":null, "_3":null, "_4":null, "i":null, "_6":null, "_7":null, "j":null, "_9":null, "$k":1, "Class":"Function"}, "find":{"_1":null, "_2":null, "_3":null, "$k":1, "Class":"Function"}, "findByKeys":{"_1":null, "_2":null, "_3":null, "_4":null, "_5":null, "_6":null, "_7":null, "_8":null, "$k":1, "Class":"Function"}, "containsProperty":{"_1":null, "_2":null, "_3":null, "$k":1, "Class":"Function"}, "findAll":{"_1":null, "_2":null, "_3":null, "l":null, "_5":null, "i":null, "_7":null, "$k":1, "Class":"Function"}, "findAllMatches":{"_1":null, "l":null, "_3":null, "_4":null, "i":null, "_6":null, "_7":null, "j":null, "_9":null, "$k":1, "Class":"Function"}, "slide":{"_1":null, "_2":null, "$k":1, "Class":"Function"}, "slideRange":{"_1":null, "_2":null, "_3":null, "_4":null, "$k":1, "Class":"Function"}, "slideList":{"_1":null, "_2":null, "_3":null, "i":null, "$k":1, "Class":"Function"}, "makeIndex":{"_1":null, "_2":null, "_3":null, "_4":null, "_5":null, "i":null, "_7":null, "_8":null, "_9":null, "$k":1, "Class":"Function"}, "arraysToObjects":{"_1":null, "_2":null, "_3":null, "i":null, "l":null, "_6":null, "p":null, "_8":null, "$k":1, "Class":"Function"}, "objectsToArrays":{"_1":null, "_2":null, "_3":null, "i":null, "l":null, "_6":null, "p":null, "_8":null, "$k":1, "Class":"Function"}, "spliceArray":{"_1":null, "_2":null, "_3":null, "_4":null, "$k":1, "Class":"Function"}, "peek":{"_1":null, "$k":1, "Class":"Function"}, "removeItem":{"_1":null, "$k":1, "Class":"Function"}, "getItem":{"_1":null, "$k":1, "Class":"Function"}, "setItem":{"_1":null, "$k":1, "Class":"Function"}, "clearAll":{"_1":null, "$k":1, "Class":"Function"}, "size":{"$k":1, "Class":"Function"}, "subList":{"_1":null, "_2":null, "$k":1, "Class":"Function"}, "addAll":{"_1":null, "$k":1, "Class":"Function"}, "removeAll":{"_1":null, "_2":null, "$k":1, "Class":"Function"}, "clear":{"$k":1, "Class":"Function"}, "toArray":{"$k":1, "Class":"Function"}, "sortByProperty":{"_1":null, "_2":null, "_3":null, "_4":null, "$k":1, "Class":"Function"}, "sortByProperties":{"_1":null, "_2":null, "i":null, "_4":null, "_5":null, "_6":null, "_7":null, "_8":null, "_9":null, "_10":null, "_11":null, "l":null, "_13":null, "_14":null, "_15":null, "_16":null, "_17":null, "$k":1, "Class":"Function"}, "unsort":{"$k":1, "Class":"Function"}, "$gj":{"_1":null, "_2":null, "_3":null, "i":null, "_5":null, "$k":1, "Class":"Function"}, "$gs":{"_1":null, "_2":null, "_3":null, "_4":null, "$k":1, "Class":"Function"}, "normalize":{"_1":null, "_2":null, "_3":null, "$k":1, "Class":"Function"}, "max":{"_1":null, "_2":null, "_3":null, "i":null, "_5":null, "$k":1, "Class":"Function"}, "min":{"_1":null, "_2":null, "_3":null, "i":null, "_5":null, "$k":1, "Class":"Function"}, "sum":{"_1":null, "_2":null, "_3":null, "i":null, "$k":1, "Class":"Function"}, "and":{"_1":null, "_2":null, "i":null, "$k":1, "Class":"Function"}, "or":{"_1":null, "_2":null, "_3":null, "i":null, "$k":1, "Class":"Function"}}
            What am I missing? How can I just get the criteria as a JSON Object?

            Thanks,
            Arend

            Comment


              #7
              criteria is an Array and JSONObject appears to be naive about this, it's treating all of the Arrays slots as normal properties.

              Recommend you send the whole criteria object. As it stands, you are dropping the outer "and" operator, which is meaningful information.

              Comment

              Working...
              X