Announcement

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

    ListGrid.ExportClientData(dsRequest) exports integers with whitespace thousand seperator

    Because of this excel is handling it as text, and I have to remove all whitespaces in excel. This does not happen when using exportData(). In ds.xml these numbers is of type localeInt. Is there a setting I can use to have the same behavior in exportClientData()?

    SmartClient Version: v9.1p_2018-03-27/PowerEdition Deployment (built 2018-03-27)

    Code:
        private HeaderControl getExportToFileControl() {
            return new HeaderControl(HeaderControl.SAVE, getExportToFileHandler());
        }
    
        private ClickHandler getExportToFileHandler() {
            return new ClickHandler() {
                public void onClick(ClickEvent event) {
                    exportToFile(ExportTool.getExportProperties());
                }
            };
        }
    
        protected void exportToFile(final DSRequest dsRequestProperties) {
            final ResultSet resultSet = mGrid.getOriginalResultSet();
            if (resultSet.allMatchingRowsCached()) {
                mGrid.exportClientData(dsRequestProperties);
                return;
            }
            mHandler = resultSet.addDataArrivedHandler(new com.smartgwt.client.data.events.DataArrivedHandler() {
                @Override
                public void onDataArrived(com.smartgwt.client.data.events.DataArrivedEvent dataArrivedEvent) {
                    mGrid.exportClientData(dsRequestProperties);
                    removeHandler();
                }
            });
            resultSet.getRange(0, resultSet.getLength());
        }
    
    public class ExportTool {
    
        public static DSRequest getExportProperties(){
            DSRequest dsRequestProperties = new DSRequest();  
            dsRequestProperties.setExportAs(ExportFormat.OOXML);
            dsRequestProperties.setExportDisplay(ExportDisplay.DOWNLOAD);
            return dsRequestProperties;
        }
    }
    Last edited by anderfim; 11 Apr 2018, 03:23.

    #2
    This is not reproducible just doing an export with fields of type "localeInt".

    Are you actually seeing whitespaces for the thousands separator when the numbers are rendered in the grid?

    Do you see this with any export target other than OOXML (eg CSV)?

    What locale are you using? Do you have this problem in the default en_US locale?

    Comment


      #3
      1) Yes, I see the whitespace as thousand seperator in grid (which is the presentation of thousand seperator in no_NB locale)
      2) Yes, I also see this when exporting with target CSV
      3) I use no_NB locale, I am sorry that I forget to give that information yesterday
      4) In the default en_US locale the whitespace is switched with a comma, and with export target OOXML excel gives me the choice to convert it to number as long as the int is not above 1 000 000, which is not an option when the thousand seperator is whitespace and the int is above 1000.

      Kind regards, Anders
      Last edited by anderfim; 11 Apr 2018, 23:28.

      Comment


        #4
        exportClientData() is a "what you see is what you get" export. If you want to be able to work with numbers in Excel, exportData() is possibly the better choice. Another option would be to use a CellFormatter that switches modes when you are exporting.

        Comment


          #5
          I had to switch from exportData() to exportClientData() because our customer wanted to get the export with the displayed columns and the sorting she had set up in the grid. I will have a look at the CellFormatter, I was not aware of that possibility :)

          Comment


            #6
            I actually solved using setExportRawValues(true), then Excel understood that it was numbers. When using CellFormatter Excel understood that it was numbers in that way that it suggested to convert it to numbers, but with this method I came all the way.

            Code:
                protected void exportToFile(final DSRequest dsRequestProperties) {
                    final ResultSet resultSet = mGrid.getOriginalResultSet();
            
                    for (ListGridField field : mGrid.getFields()) {
                        if(field.getType() != null && (isLocaleInt(field) || isInteger(field))) {
                            field.setExportRawValues(true);
                        }
                    }
            
                    if (resultSet.allMatchingRowsCached()) {
                        mGrid.exportClientData(dsRequestProperties);
                        return;
                    }
                    mHandler = resultSet.addDataArrivedHandler(new com.smartgwt.client.data.events.DataArrivedHandler() {
                        @Override
                        public void onDataArrived(com.smartgwt.client.data.events.DataArrivedEvent dataArrivedEvent) {
                            mGrid.exportClientData(dsRequestProperties);
                            removeHandler();
                        }
                    });
                    resultSet.getRange(0, resultSet.getLength());
                }
            
                private boolean isInteger(ListGridField field) {
                    return field.getType().getValue().equals(ListGridFieldType.INTEGER.getValue());
                }
            
                private boolean isLocaleInt(ListGridField field) {
                    return field.getType().getValue().equals(ListGridFieldType.LOCALEINT.getValue());
                }

            Comment

            Working...
            X