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

Problems with numeric sorting

2 Answers 548 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ketil
Top achievements
Rank 1
Ketil asked on 02 Dec 2013, 04:17 PM
Hi,

I am a experience developer but a completely Kendo newbie and doing some initial tests to see if this can be a platform for our application. I have gotten a grid to work loading data from my database. But, I cannot get sorting for function for the numeric column, it always sorts as a string. I have created a model where the data type is set as number, and according to my understanding this should now parse the json data into that model and then the grid should know that this is a number, but it stills sorts as a string. Data comes from json, one line looks like this:

{"orderId":"65-68455-0b0b7","transact":"414583245","id":"414583245","paytype":"VISA","amount":"7200.00","amountBase":720000,"currency":"NOK","currencyCode":578,"test":"1","time":"2011-03-03 21:53:15","cardnomask":"XXXXXXXXXXXX0000","cardcountry":null,"refunded":0,"refundable":720000,"pids":[68455],"receipt":{"68455":false},"persons":"KEtil Test"}

My code looks like this:
$(document).ready(function() {
 
var transactionModel = kendo.data.Model.define({
    fields: {
        id: "transact",
        persons: {
            editable: false
        },
        time: {
            editable: false,
            type: "date",
        },
        transact: {
            editable: false
        },
        amount: {
            editable: false,
            type: "number",
        },
    }
});
 
var dataSource = new kendo.data.DataSource({
transport : {
read : "/wwwdocs/ajax.php",
schema : {
data : transactionModel
},
},
}
);
 
$(function() {
$("#transactions").kendoGrid({
dataSource : dataSource,
columns : [ {
field : "persons",
title : "Navn",
width : 300
}, {
field : "time",
title : "Tid",
width : 160,
}, {
field : "transact",
title : "Transaksjons-id",
width : 160
}, {
field : "amount",
title : "Sum",
width : 160
}, ],
filterable : true,
sortable : true,
groupable: true,
});
});
});

2 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 02 Dec 2013, 05:02 PM
Hi Ketil,

Thank you for getting in touch with us.

Your understanding about the model, field type and parsing is correct. The problem comes from the syntax mistakes in the code which you provided:

1. transactionModel should be assigned to the dataSource.schema.model
var dataSource = new kendo.data.DataSource({
    transport : {
        read : "/wwwdocs/ajax.php",
    },
    schema : {
        model: transactionModel
    }
});

2. The model ID is not at the right place either
var transactionModel = kendo.data.Model.define({
    id: "transact",
    fields: {
        persons: {
            editable: false
        },
        time: {
            editable: false,
            type: "date",
        },
        transact: {
            editable: false
        },
        amount: {
            editable: false,
            type: "number",
        }
    }
});


I hope this will help.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ketil
Top achievements
Rank 1
answered on 02 Dec 2013, 05:18 PM
Thanks, that did the trick. 
Tags
Grid
Asked by
Ketil
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Ketil
Top achievements
Rank 1
Share this question
or