Results 1 to 5 of 5

Thread: GridView columns won't sort correctly despite of correct type

  1. #1
    Ext JS Premium Member
    Join Date
    Sep 2010
    Location
    Jyderup, Denmark
    Posts
    51

    Question GridView columns won't sort correctly despite of correct type

    Hi

    I have a gridpanel with the following columns:

    Code:
    columns: [
         {header: "Name", width: 130, dataIndex: 'name', sortable: true},
         {header: "Manufacturer", dataIndex: 'manufacturer', sortable: true},
         {header: "Country", dataIndex: 'country', sortable: true},
         {header: "Price", renderer: Ext.util.Format.numberRenderer("0,000"), dataIndex: 'price', sortable: true},
         {header: "Max Power (BHP)", type: 'int', dataIndex: 'bhp', sortable: true},
         {header: "Drivetrain", dataIndex: 'drivetrain', sortable: true},
         {header: "Weight (kg)", dataIndex: 'weight', sortable: true}
    ]
    I want it to sort the numbers right when clicking the header of a column containing numeric values. I've tried setting the value property to 'int' but the data is still sorted as if it strings instead of numbers...

    The full code is here (I've built upon the Bookstore ExtJS example, so naming of all the components are book specific and not car specific):

    http://gran-turismodb.com/car-db/index2.php


    Does anyone have a clue as to what I'm doing wrong?

  2. #2
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750

    Default

    I'm not certain where you got the "type" config option for an Ext.grid.Column, but you should be specifying "type: 'int'" in your JsonReader's fields definition instead.

  3. #3
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750

    Default

    From your code:

    Code:
     
    Ext.applyIf(config, {
      reader: new Ext.data.JsonReader({
        root: 'cars',
        idProperty: 'carID' // <-- you had a trailing comma here
      }, [
        {name: 'carID'},
        // ... so on
        {name: 'bhp', type: 'int'}, // <-- adding the type here should take care of your sorting issue
        // ...     
       ])
    });

  4. #4
    Ext JS Premium Member
    Join Date
    Sep 2010
    Location
    Jyderup, Denmark
    Posts
    51

    Default

    Yes! That did the trick.

    You are totally right, the type shouldn't be on the column but the JsonReader - I got it mixed up, while reading the documentation.

    Thank you very much, fay

  5. #5
    Touch Premium Member msinn's Avatar
    Join Date
    Jul 2009
    Location
    in front of my pc
    Posts
    280

    Default

    try for the column with numeric values this:

    {header: "Price", xtype:'numbercolumn', format:'0,000', dataIndex: 'price', sortable: true},

    take a look to the column xtypes and Column subclasses, they have own renderers
    http://dev.sencha.com/deploy/dev/doc...xt.grid.Column?member=xtype

    you may also take a look to the number formats

    http://dev.sencha.com/deploy/dev/doc...xt.util.Format?member=number
    First I would like to thank you for your time and knowledge

    Win 7 Ext JS 4.1.3 IE(6-9), FF17

Similar Threads

  1. Sortable Columns: Remove 'Sort Ascending,' 'Sort Descending' Options
    By Mahendru in forum Ext 3.x: Help & Discussion
    Replies: 10
    Last Post: 5 Mar 2013, 11:04 PM
  2. Correct way to determine type of subpanels
    By irata in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 17 Jun 2010, 8:46 AM
  3. Replies: 12
    Last Post: 1 Dec 2009, 9:07 AM
  4. Replies: 13
    Last Post: 14 Jun 2009, 5:59 PM
  5. What is the correct doc type?
    By zeroed in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 23 Feb 2009, 1:07 PM

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
  •