0

次のように構成されたデータグリッドがあります。

<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などの任意の列を最初にクリックすると、昇順で並べ替えられますが、これは問題ありません。2 回目のクリックでは、降順で並べ替えられます。これも想定どおりの動作です。ただし、3回目のクリックでは何も起こらず、コンソールに「Uncaught TypeError: Cannot read property 'field' of undefined」と表示されます。これは、2 回連続してクリックした後に data.sort 配列に何かが発生することを意味します。

ポインタをいただければ幸いです。

4

2 に答える 2

0

3 回目のクリックで、並べ替えが削除されます。次のようにスクリプトを変更できます。

 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;

 }
于 2015-01-08T22:01:07.420 に答える