Results 1 to 7 of 7

Thread: Model sortType function ignored when clicking a grid column header

  1. #1
    Sencha User
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    26
    Answers
    2

    Default Model sortType function ignored when clicking a grid column header

    I'm using a sortType function on my model and this works when the grid first loads data. However, when I click the column header the sortType function is ignored and the rows are sorted alphabetically instead.

    How can I get the grid to respect my sortType function?

  2. #2
    Sencha User yeghikyan's Avatar
    Join Date
    Mar 2009
    Location
    München
    Posts
    574
    Answers
    99

    Default

    what about code?
    "The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague." – Edsger W. Dijkstra

  3. #3
    Sencha User
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    26
    Answers
    2

    Default

    On the model:

    Code:
        {
          name: 'status',
          type: 'string',
          sortType: function (value) {
            switch (value) {
              case 'awaiting-action': return 1;
              case 'screening':       return 2;
              case 'cv-out':          return 3;
              case 'interviewing':    return 4;
              case 'offer':           return 5;
              case 'accepted':        return 6;
              case 'declined':        return 7;
              case 'rejected':        return 8;
              case 'uncontactable':   return 9;
            }
            return 0;
          }
        }
    On the grid:
    Code:
      store: {
        ...
        sorters: {
          property: 'status',
          direction: 'ASC'
        }
      }

  4. #4
    Sencha User yeghikyan's Avatar
    Join Date
    Mar 2009
    Location
    München
    Posts
    574
    Answers
    99

    Default

    not enough code, jedenfalls here it works...

    WOW, inline fiddle!!!!
    "The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague." – Edsger W. Dijkstra

  5. #5
    Sencha User
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    26
    Answers
    2

    Default

    I think the problem exists because I'm using 2 fields. I have a second field statusFormatted on the model which formats the status string using a calculate method.
    1. status = "awaiting-action"
    2. statusFormatted = "Awaiting Action"
    I use statusFormatted as the grid column and sort by status. Ideally I need to sort by statusFormatted but I can't do this because the sortType method can't access the status property.

  6. #6
    Sencha User yeghikyan's Avatar
    Join Date
    Mar 2009
    Location
    München
    Posts
    574
    Answers
    99

    Default

    In my humble opinion, the problem is in Do Not Repeat Yourself (http://en.wikipedia.org/wiki/Don%27t_repeat_yourself)
    You could get from server only status codes and represent it with renderer mechanism of column.
    In the util class you could put a function which would translate status code to human readable value and after that operate only with the status numeric codes...
    Afterwords when you will begin translation/localisation implementation you will have problem by such a manner of coding... and not only there.
    "The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague." – Edsger W. Dijkstra

  7. #7
    Sencha User
    Join Date
    Mar 2009
    Location
    United Kingdom
    Posts
    26
    Answers
    2

    Default

    Thanks for your advice. I managed to get it working in the end by implementing your suggestion.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •