I am encountering an issue with my kendogrid where numbers are not sorting correctly; they seem to be sorting as strings instead of actual numerical values. For example, when trying to sort a column from 1 to 10, instead of getting 1,2,3,4,5,6,7,8,9,10, I get 1,10,2,3, and so on.
The data being fed into the grid is in the form of a JSON array. The specific column I am attempting to sort on is the Id column. I have previously managed to successfully implement sorting by pulling the data directly from the server; however, that approach is not applicable in this scenario.
Here is my html code:
<div id="myGrid" kendo-grid="myGrid"
k-options="myGridOptions"></div>
This is my JavaScript code:
var myModel = kendo.data.Model.define({
id: "Id",
fields: $scope.myColumns
});
$scope.myDataSource = new kendo.data.DataSource({
data: $scope.data,
pageSize: 10,
sort: [{field:"Id", dir:"asc"}],
schema: {
model: myModel
}
});
$scope.myColumns = [
{ field: 'Id',title: 'ID',width:"80px", type:"number" },
{ field: 'amount',title: 'Amount',width:"130px",type:"number" }
];
$scope.myGridOptions = {
dataSource: $scope.myDataSource,
reorderable: true,
groupable: false,
sortable: {
allowUnsort: false,
},
selectable: "multiple, row",
pageable: {
pageSize: 20,
pageSizes: [10, 20, 50],
},
columns: $scope.myColumns,
};