This is a migrated thread and some comments may be shown as answers.

Numeric vs alphabetical sorting

3 Answers 261 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
PPCnSEO
Top achievements
Rank 1
PPCnSEO asked on 20 Apr 2012, 07:59 AM
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?

3 Answers, 1 is accepted

Sort by
0
Gergo
Top achievements
Rank 1
answered on 20 Apr 2012, 09:36 PM
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ő
0
Sean
Top achievements
Rank 1
answered on 02 Nov 2012, 12:11 AM
Is there any other way to specify the data type?

Ive tried everything and cant get my data to sort numericly
0
Sean
Top achievements
Rank 1
answered on 08 Nov 2012, 12:00 AM
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
Tags
Data Source
Asked by
PPCnSEO
Top achievements
Rank 1
Answers by
Gergo
Top achievements
Rank 1
Sean
Top achievements
Rank 1
Share this question
or