Angularjs KendoUI Grid的DataSource parametermap的data.sort数组在第三列排序时变为未定义
我有一个datagrid,配置如下:Angularjs KendoUI Grid的DataSource parametermap的data.sort数组在第三列排序时变为未定义,angularjs,kendo-ui,kendo-grid,kendo-datasource,Angularjs,Kendo Ui,Kendo Grid,Kendo Datasource,我有一个datagrid,配置如下: <script> angular.module("KendoDemos", [ "kendo.directives" ]); function MyCtrl($scope) { $scope.mainGridOptions = { dataSource: { transport: { read: { url: "http://
<script>
angular.module("KendoDemos", [ "kendo.directives" ]);
function MyCtrl($scope) {
$scope.mainGridOptions = {
dataSource: {
transport: {
read: {
url: "http://localhost:8090/rest/mycodeapi/Salesman?app_name=mycode&fields=FirstName%2C%20LastName&include_count=true",
dataType : 'jsonp',
type: 'GET',
beforeSend: function (req) {
req.setRequestHeader('Authorization', 'b3pilsnuhsppon2qmcmsf7uvj6')
}
},
parameterMap: function(data, type) {
if (type == "read") {
// send take as "$top" and skip as "$skip"
return {
order: data.sort[0]['field'] + ' ' + data.sort[0]['dir'],
limit: data.pageSize,
offset: data.skip
};
}
}
},
schema: {
data : 'record',
total: 'meta.count'
},
pageSize: 5,
serverPaging: true,
serverSorting: true,
sort: { field: "SalesmanID", dir: "asc" }
},
sortable: true,
pageable: true,
mobile: 'phone',
columns: [{
field: "FirstName",
title: "First Name"
},{
field: "LastName",
title: "Last Name"
}]
};
}
</script>
问题是:第一次单击任何列(比如FirstName)时,它会按升序排序,这很好。
在第二次单击时,它按降序排序:仍然是预期的行为。
但是,在第三次单击时,什么也没有发生,控制台显示未捕获的TypeError:无法读取未定义的属性“field”。这意味着在连续第二次单击后,data.sort数组发生了一些事情
如有任何提示,将不胜感激。第三次单击时,排序将被删除。您可以修改脚本,如下所示:
if (type == "read") {
var params = {
limit: data.pageSize,
offset: data.skip
};
if (data.sort && data.sort.length > 0)
params.order = data.sort[0]['field'] + ' ' + data.sort[0]['dir'];
return params;
}
我知道这有点晚了,但我也面临着同样的挑战,这就是我为解决这个问题所做的 改变
sortable: true,
到
sortable: {
allowUnsort: false
},