当我在ui-grid中外部过滤数据时,在我的成功函数中,我看到从我的服务返回的正确过滤的数据。但是当我应用它时,网格是空的。
最初,没有过滤器,我得到了我期望的所有结果。
知道为什么数据没有出现?
app.controller('GridController', ['$scope', '$http', 'uiGridConstants', function ($scope, $http, uiGridConstants) {
var paginationOptions = {
pageNumber: 1,
pageSize: 25,
sort: null
};
$scope.gridOptions = {
enableFiltering: true,
useExternalSorting: false,
paginationPageSizes: [25, 50, 75],
paginationPageSize: 25,
useExternalPagination: true,
columnDefs: Mapping(type, $scope),
onRegisterApi: function (gridApi) {
$scope.gridApi = gridApi;
$scope.gridApi.core.on.filterChanged($scope, function () {
HandleFiltering(this.grid.columns);
});
$scope.gridApi.core.on.sortChanged($scope, function (grid, sortColumns) {
if (sortColumns.length == 0) {
paginationOptions.sort = null;
} else {
paginationOptions.sort = sortColumns[0].sort.direction;
}
Get();
});
gridApi.pagination.on.paginationChanged($scope, function (newPage, pageSize) {
paginationOptions.pageNumber = newPage;
paginationOptions.pageSize = pageSize;
Get();
});
}
};
var HandleFiltering = function (gridColumns) {
for (var i = 0; i < gridColumns.length; i++)
{
CreateFilterObject(gridColumns[i], $scope);
}
Get();
}
var Get = function () {
debugger;
AjaxStart();
var searchRequest = SearchRequest(paginationOptions.pageNumber,
paginationOptions.pageSize,
$scope.objectFilter);
$.ajax({
type: "Post",
url: Service+ "/api/" + type + "/Search",
data: searchRequest,
success: function (data) {
$scope.gridOptions.totalItems = data[0];
$scope.gridOptions.data = data[1];
var firstRow = (paginationOptions.pageNumber - 1) * paginationOptions.pageSize;
debugger;
$scope.$apply();
AjaxEnd();
},
error: function (event, response, ajaxSettings, thrownError) {
AjaxError(response);
AjaxEnd();
},
});
}
Get();
}]);