Announcement

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

    Filtering numeric data

    I created a listgrid with a filter in SmartGwt 2.0. The listgrid has integer data and float data as well as strings.

    When the user tries to filter the numeric data, it acts like "contains" - entering "1" will match "21" or "517" or any number with a 1.

    When I user FilterBuilder to create a custom filter, the only options available for numeric fields in the drop down menu are equals, greater than, etc. Contains is not an option, as it is for text data.

    Is there a way for the filter on a listgrid to treat the data as an Integer - the same as FilterBuilder? That is, do "equals" semantics rather than "contains"?

    The field is set to Integer type in the Data source, and I also tried setting filter editor type to IntegerItem.

    Note: this is a problem for us because we do lazy fetching on a large set of data. So, the server has to handle the filtering until all the data is cached. It's not easy to do "contains" on an integer in SQL or Java.

    TIA!

    #2
    Which behavior do you actually want from a UI design perspective? If it's "contains", contains is pretty trivial in SQL - just run our server product and look at what we generate.

    Comment


      #3
      Thanks for the reply. Ideally, we would prefer the equals semantics. Is there a way to get that behavior?

      I'm afraid I don't have access to your server product. For our Informix database, a "contains" in SQL is "field like "%Y%", and that is illegal against an integer field.

      Comment


        #4
        Everybody has access to our server product for something like this, the eval is a free download.

        You can set FormItem.operator via ListGridField.setFilterEditorType() and this will cause client-side filtering to use a different operator. This also means DataSources will send AdvancedCriteria rather than the simpler Criteria structure, so you'll need to handle that on your server.

        Comment


          #5
          Its easy to do a like on an integer field in SQL, just cast it to a string first. I use postgres and in that you just do CAST(Field AS TEXT) LIKE '%Y%' not sure if that works in every database, but it should at least be similar.

          And if you are writing your own server code can't you just ignore the client whenever it requests contains on an integer field and do equals instead?

          Comment


            #6
            Thanks for the reply!

            I tried calling setFilterEditortype with IntegerItem (since Integers in FilterBuilder don't have the contains semantics), but that didn't help.

            I'm sorry if I'm being obtuse, but what input should I provide to setFilterEditorType to get the equals behavior?

            My server already supports AdvancedCriteria, so that isn't an issue.

            mhulsman - thanks for the suggestion! I haven't used CAST with LIKE before, so that gives me a few more options.

            Comment


              #7
              Pass a FormItem on which you have called setOperator().

              Comment


                #8
                That's worked great! Thank you!

                Comment


                  #9
                  When I try to use this:

                  Code:
                  ListGridField httpPortField = new ListGridField("httpPort","HTTPort",50);
                  httpPortField.setType(ListGridFieldType.INTEGER);
                  httpPortField.setFilterOperator(OperatorId.EQUALS);
                  		
                  httpPortField.setCanFilter(true);
                  IntegerItem intItem = new IntegerItem();
                  intItem.setOperator(OperatorId.EQUALS);
                  httpPortField.setFilterEditorType(intItem);
                  		
                  serverGrid.setFields(httpPortField);
                  Datasource:
                  Code:
                  DataSourceIntegerField httpPortField = new DataSourceIntegerField("httpPort","HTTP Port",5,true);
                  The value gets submitted with the correct operator, but the value in the fieldEditor disappears. The following error appears:

                  Code:
                  TMR5:WARN:ListGrid:isc_ListGrid_0:Advanced criteria includes criteria for field:httpPort with operator equals. Unable to display this type of criteria in the filter editor.
                  com.smartgwt.client.core.JsObject$SGWT_WARN: 12:47:26.708:TMR5:WARN:ListGrid:isc_ListGrid_0:Advanced criteria includes criteria for field:httpPort with operator equals. Unable to display this type of criteria in the filter editor.
                      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
                      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
                      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
                      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
                      at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:105)
                      at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
                      at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:157)
                      at com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:1668)
                      at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:401)
                      at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222)
                      at java.lang.Thread.run(Thread.java:619)

                  Comment


                    #10
                    Hi,
                    I'm using smartgwt version 2.2 and I'm trying create dynamical adaptive filters above the grid. That's means, I generate a grid and fill in it by data. After that I set on some listgridfield operator iEquals. But the behaviour of component isn't changed. Client still searching with operator iContains.

                    I changed this by menu at columnHeader.
                    Code:
                    final MenuItem equalsSM = new MenuItem(Common.msg.equalsOperator());
                    equalsSM.setChecked(OperatorId.EQUALS.equals(getField(fieldNum).getFilterOperator()));
                    equalsSM.setAttribute("operator", OperatorId.EQUALS);
                    equalsSM.addClickHandler(new ClickHandler() {
                        public void onClick(MenuItemClickEvent event) {
                            for (OperatorId operatorId : OperatorId.values()) {
                                if(operatorId.getValue().equals(event.getItem().getAttribute("operator"))) {
                                    event.getItem().setChecked(true);
                                    getField(event.getColNum()).setFilterOperator(operatorId);
                                    IntegerItem intItem = new IntegerItem();
                                    intItem.setOperator(operatorId);
                                    getField(event.getColNum()).setFilterEditorType(intItem);
                                }
                            }
                        }
                    );

                    And the question sounds: Is there any possibility to change operator of the filter field after generate grid with data?
                    Last edited by zaky.vit; 11 Oct 2010, 06:25.

                    Comment


                      #11
                      Originally posted by mhulsman
                      Its easy to do a like on an integer field in SQL, just cast it to a string first. I use postgres and in that you just do CAST(Field AS TEXT) LIKE '%Y%' not sure if that works in every database, but it should at least be similar.

                      And if you are writing your own server code can't you just ignore the client whenever it requests contains on an integer field and do equals instead?
                      Hi, I am trying to do exactly this. say the list contains integer 123, and it should return when I search for "23". how exactly do you specify the integer field and the "CAST as TEXT"? thanks!

                      Comment

                      Working...
                      X