Announcement

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

  • LocaleFloat Filter is not working

    Hello,

    I have some strange behaviour with a ListGrid and a LocaleFloat field. We have a ListGrid with filterOnKeyPress = true and a field with the data type LOCALEFLOAT. After I insert a filter on this field the localized formats are converted to English format. For example, 1,000,123 becomes 1,000,123. The server-side filter works, but it looks a bit strange to the user.

    We use SmartGWT 6.0-p20181006 (Power edition) and the latest Chrome version.

    I tried also the newer versions of SmartGWT 6.1-p20181006 (Power edition) and the 12.0-p20181009 (Eval edition). In this version, the behavior is completely useless. After inserting a filter in this LOCALEFLOAT field the value disapears. In the request, I see that the criteria is sent to the server with the correct value. The filters of the other fields (data types) work as expected for all three versions.

    Could you please help me with this problem?


  • #2
    Can you show us how to reproduce this issue? Simplest thing would be if you can take a framework sample, switch a field to localeFloat, and in addition tell us what locale you are loading.

    Comment


    • #3
      I used the "GridDataTypesDecimalSample" from the showcase for the test and modified the fileld type of the field "gdp" to LOCALEFLOAT (see code below).

      The behavior is the same as in our code. To test, please do the following (take a look also to the screenshots).
      • Start application with the local "de_DE" (The GWT project is compiled with locale "en_US" and "de_DE" )
      • Enter a decimal value in the FilterEditor, e.g. "12360.01"
      • Execute filter
      • Then the formatting in the FilterEditor is discarded. Here in this example "1236001".
      What are we doing wrong?

      Code:
      Canvas canvas = new Canvas();
      
      final ListGrid countryGrid = new ListGrid();
      
      countryGrid.setWidth(350);
      countryGrid.setHeight(224);
      countryGrid.setShowAllRecords(true);
      countryGrid.setCanEdit(true);
      countryGrid.setEditEvent(ListGridEditEvent.CLICK);
      countryGrid.setModalEditing(true);
      countryGrid.setShowFilterEditor(true);
      
      ListGridField nameField = new ListGridField("countryName", "Country");
      ListGridField gdpField = new ListGridField("gdp", "GDP ($B)");
      gdpField.setType(ListGridFieldType.LOCALEFLOAT);
      gdpField.setCellFormatter(new CellFormatter()
      {    
         public String format(Object value, ListGridRecord record, int rowNum, int colNum)    
        {        
          if ( value == null )        
          {
             return null;
           }        
           NumberFormat nf = NumberFormat.getFormat("#,##0.00");        
           try
          {
            return nf.format(((Number) value).floatValue());
           }
           catch ( Exception e )        
          {
             return value.toString();        
           }    
        }
      });  
      
      countryGrid.setFields(new ListGridField[] { nameField, gdpField });
      countryGrid.setData(CountrySampleData.getRecords());
      canvas.addChild(countryGrid);  
      
      canvas.draw();
      Attached Files
      Last edited by EISENMANN; 6th Nov 2018, 00:00.

      Comment


      • #4
        The sample you posted doesn't work because there's no DataSource on the grid - see your browser console for warnings about that.

        If we fix that issue, we do see a problem where the formatting is removed from the localeFloat *in the filter-editor* when the server returns.

        That seems to be what you are pointing out in your most recent post, and we'll address that.

        However, your initial post seemed to be saying something quite different - that "After I insert a filter on this field the localized formats are converted to English format" -- but the example you gave showed two identical formats - "For example, 1,000,123 becomes 1,000,123".

        We don't see any behavior like that in testing.
        Last edited by Isomorphic; 7th Nov 2018, 04:53.

        Comment


        • #5
          Quick follow-up - if what you expect is to be able to search for localeFloat values using your custom format, then you just need to add a FormItemValueFormatter via the field's filterEditorProperties.

          So, get rid of your call to setData() and then add an identical formatter to the filter formItem, like this:

          Code:
                  FormItem editor = new FormItem();
                  editor.setEditorValueFormatter(new FormItemValueFormatter() {
          
                      @Override
                      public String formatValue(Object value, Record record, DynamicForm form,
                              FormItem item) {
                          if ( value == null )        
                          {
                             return null;
                           }        
                           NumberFormat nf = NumberFormat.getFormat("#,##0.00");
                           try
                          {
                            return nf.format(((Number) value).floatValue());
                           }
                           catch ( Exception e )        
                          {
                             return value.toString();        
                           }    
                      }
                  });
                  gdpField.setFilterEditorProperties(editor);
          
                  countryGrid.setDataSource(DataSource.get("countryDS"));
                  countryGrid.setAutoFetchData(true);
          This will allow you to type in values with or without the thousands separator char, and the value will be reformatted to include them - but if you include decimal places, you must use the correct character ("," in your case) or the decimal portion will be removed.

          Comment


          • #6
            Sorry, yes you are right I had a a typo in my first post. I had as locale "de_DE" and insert "1.000,123" and the value in the editor changed after executing the filter to "1000.123" (English format).
            This behavior is in our whole application.

            And also sorry for the bad showcase example, we don't want to add a separate ValueFormatter to the field nor to the editor. We only want to use the "LOCALEFLOAT" type with an SQL DataSource.

            You mentioned "If we fix that issue, we do see a problem where the formatting is removed from the localeFloat *in the filter-editor* when the server returns.
            That seems to be what you are pointing out in your most recent post, and we'll address that.". This seems exactly to be our problem., the LOCALFLOAT fields does not keep the local format after executing the filter.

            Comment


            • #7
              Yes - and it's because you don't have a formatter applied to the filterEditor field.

              When you say "we don't want to add a separate ValueFormatter to the field nor to the editor" - if you want the filterEditor to show the format you want, then you will have to - that's how it's done.

              We mentioned seeing that issue before we realised the reason for it -

              To show the formatted (locale-specific) value in the filterEditor, you need to format the edit value - and you would do that by setting a value formatter on the field's filter editor item.

              If you dont want to apply that formatter, then you can just tab out of the field to see the format you're after.

              Last edited by Isomorphic; 8th Nov 2018, 22:51.

              Comment


              • #8
                Just for clarity on this - if your problem is that filtering didn't work at all, that was because there was no dataSource, and there were warnings about that in the console.

                If your problem is that formatting is removed from the filter field, that's because the field is in edit mode, and you're editing a float - localeFloat applies a display format, not an edit format - if you want to enter edit values in your locale format (such as in a filter filed), you need to apply a formatter to the edit value.

                Comment

                Working...
                X