Kendo UI Server端排序和过滤

时间:2015-04-24 09:10:56

标签: kendo-ui kendo-grid

下面给出了通过服务调用API的kendo dataSource。

很难确定是否触发了排序或过滤事件。

var dataSource = new kendo.data.DataSource({
                transport: {
                      // read : "/scripts/data/products/categoryLabel.json", 
                        read : function(options){
                          // alert(options.data.page + "-" + options.data.pageSize);
                            console.log("Read options : " , options);
                            var order_by;
                            if (options.data.sort) {
                                if (options.data.sort.length > 0) {
                                    var sortField = options.data.sort[0].field;
                                    if (options.data.sort[0].dir == 'asc') {
                                        var sortOrder = '';
                                    }
                                    else if (options.data.sort[0].dir == 'desc') {
                                        var sortOrder = '-';
                                    };
                                    order_by = sortOrder + sortField;
                                }
                            }
                            if (options.data && options.data.filter && options.data.filter.filters) {
                                config ={  
                                    value: options.data.filter.filters[0].value, 
                                    field: options.data.filter.filters[0].field, 
                                    accountId: $scope.model.adAccount.accounts.selected.aa_id,
                                    category_id  : null,
                                };
                                console.log("input: ", options.data.filter.filters[0])
                            }
                            Campaignlabel.fetchCategorycampaign(config, order_by, options.data.page, options.data.pageSize).success(function (fetchCampaignlabel) {
                                $scope.model.totalCount = fetchCampaignlabel.count;
                                options.columns = $scope.model.columns;
                                options.success(fetchCampaignlabel.results); 
                                // config = null;
                            }).error(function (fetchCampaignlabel) { 
                                options.error(fetchCampaignlabel.results);
                            });
                        },
                    },

                pageable : true,
                pageSize:50,
                serverPaging: true, 
                reorderable: true,
                sortable :true,
                page : 1,
                serverFiltering: true,
                serverSorting: true,
                schema: {
                   total: function (result) {
                            result = result.data || result; 
                            return $scope.model.totalCount;
                        },
                   model: {
                       id : "campaign_id",
                       fields: { 
                           Select : {type : "boolean"},
                           category: { editable: false, type: 'number'},
                           campaign_id: { editable: false, type: 'number'},
                           name: { editable: false, type : "string" },
                           objective: { editable: false, type : "string" },
                           status: { editable: false, type : "string" }, 
                           category_name: { editable: false },
                           start_time : { editable: false, type: "date"},
                       }
                   }
              },  

            }); 

请在此建议以任何方式识别过滤器或排序事件。

0 个答案:

没有答案