Numeric vs alphabetical sorting

4 posts, 0 answers
  1. PPCnSEO
    PPCnSEO avatar
    16 posts
    Member since:
    Nov 2011

    Posted 20 Apr 2012 Link to this post

    I have a grid attached to a datasource with local sorting enabled.

    One of the columns contains a list of numbers collected from an integer column of a database, so every value is definitely numeric.

    What I would expect in this instance is numerical sorting but instead it is doing alphabetical as though it was text not numbers.
    eg. 0, 1, 23, 3, 45, 54, 6, 76, 8

    Does kendo automatically detect the datatype of a column to determine suitable sorting?
    Or can we specify the datatype of individual columns ourselves?
  2. Gergo
    Gergo avatar
    20 posts
    Member since:
    Mar 2012

    Posted 20 Apr 2012 Link to this post

    Hi PPCnSEO,

    You can use a model for the data shown in the grid. In the model you can specify the data type of each column.
    You can define a model like this:
    var myModel = kendo.data.Model.define({
            id: "id",
            fields: {
                id: { type: "number" },
                field1: { type: "date" },
                field2 { type: "string" }
            }
        });

    After that you can use this model when creating the datasource for your grid:

    var myDS= new kendo.data.DataSource({
            transport: {
                read: {
                    url: "myController/GetMyData",
                    dataType: "json"
                }
            },
            schema: {
                model: myModel       
            }
        });

    Hope this helps.

    Kind Regards,
    Gergő
  3. Kendo UI is VS 2017 Ready
  4. Sean
    Sean avatar
    15 posts
    Member since:
    Sep 2008

    Posted 01 Nov 2012 Link to this post

    Is there any other way to specify the data type?

    Ive tried everything and cant get my data to sort numericly
  5. Sean
    Sean avatar
    15 posts
    Member since:
    Sep 2008

    Posted 07 Nov 2012 Link to this post

    I used a schema model to specify data type but n2 and number dont sort the same way n2 seems to sort alphabetically and number sorts numerically
Back to Top
Kendo UI is VS 2017 Ready