Announcement

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

    Sorting and foreign language characters

    If this has an obvious answer, i apologize in advance.

    I am trying the sort functions for the listgrid. I would like them sorted alphabetically, but with for example the Swedish characters Å, Ä, Ö after Z. This is the way our user will expect it to be.

    When i configure sort on the grid, they appear in the same spot as 'A'.

    What is the supposed way to solve this?

    EDIT: one more question regarding sort:
    I have a 'master/detail' approach with a form where the users enter new records. When something is created with the datasource, items do not appear according to the listgrid sort configured, but at the end of the list.

    I would like them sorted, and also the row selected in the grid. For this, i have solved this with a savedListener on the form:
    Code:
    form.addSavedListener((records, newRecord, isDataDirty) -> {
        listGrid.sort();
        listGrid.deselectAllRecords();
        listGrid.selectRecord(records[0]);
    });
    It would be neat if new items were just inserted in the grid according to the sort, but am i doing this right or is there a better way?

    Thanks.
    Last edited by mathias; 10 Oct 2020, 03:05.

    #2
    First question: we use the browser's provided localeCompare() function. If you are in a Swedish locale and you're not getting the expected sort, you probably want to file a bug with the browser vendor (and you may find that some browser/platform combinations work and others don't). Your other option would be to provide your own sortNormalizer, but since you've have to go character by character doing comparisons, it probably wouldn't perform adequately for more than around 200 records.

    Second question: you should see automatic sorting into place if all rows are loaded. Otherwise, see resultSet.updatePartialCache - we try to keep the record in the viewport, and automatically unsort the list (because the only way to sort into place correctly would be to drop current cache).

    Comment


      #3
      Hi mathias,

      this thread is related.

      Best regards
      Blama

      Comment


        #4
        OK thanks. What you're saying is true, i depends on the locale (i had english). What i'd like then is to be able to manually set the locale that affects the sorting (we have a user account setting that would be neat to use).

        Comment


          #5
          Generally the locale is determined by HTTP header negotiation, there isn't a way to programmatically change the current locale via JavaScript. So while you can change the GWT / SmartGWT concept of locale and have all the date formats and end user messages change, we can't actually make the native localCompare function operate differently.

          To really really change locale so that collation is affected, you will likely have to guide the user through language preferences dialogs that may differ by browser (we know, that sucks).

          On some newer browsers, it is now possible to pass a locale to the localCompare function, so that you could get sorting in Swedish locale even if the user's browser is configured for English. We haven't done this yet because it would leave out a number of browsers that are still common, but it would be a valid Feature Sponsorship to have it added with documented caveats re: browser support.

          Comment


            #6
            Yeah, well it's not really a big deal, i just saw it and you know, sometimes you just end up looking at stuff... :) Our customers have always had it like this, so it is what it is i guess. Thanks for all the input.

            Comment

            Working...
            X