我正在学习angular.js和新使用ng-table指令。我将数据分组,然后使用ng-table显示它们。我能够查看过滤后的数据,但无法进行排序或过滤。有人可以帮我吗这是代码。谢谢!
http://plnkr.co/edit/x5NKwcxHhui9xBItqk3K?p=preview
我正在使用第112行的ng-table->
{{sample.Field1}}
{{sample.Field4}}
{{sample.Field5}}
{{sample.Field6}}
{{sample.Field7}}
{{sample.Field8}}
{{sample.Field9}}
在script.js文件中,代码
$scope.setCurrentSample = function(
options) {
$scope.homeview = false;
$scope.showdetail = false;
$scope.drilldown = true;
console.log("optionsxx = " + options.Field1);
$scope.myCurrentSample = _(
$scope.samples).chain()
.where(options).value();
var data1 = $scope.myCurrentSample;
$scope['test_ngtable'] = new ngTableParams({
page: 1, // show first page
count: 10, // count per page
filter: {
Field5: 'TRUE' // initial filter
},
sorting: {
Field1: 'asc' // initial sorting
}
}, {
total: data1.length, // length of data
getData: function($defer, params) {
console.log("total = " + data1.length);
// use build-in angular filter
var filteredData = params.filter() ?
$filter('filter')(data1, params.filter()) :
data1;
var orderedData = params.sorting() ?
$filter('orderBy')(filteredData, params.orderBy()) :
data1;
console.log("order by " + params.orderBy());
params.total(orderedData.length); // set total for recalc pagination
$defer.resolve(orderedData.slice((params.page() - 1) * params.count(), params.page() * params.count()));
}
});
};
最佳答案
<tr ng-repeat="sample in myCurrentSample | filter:search ">
首先你需要用这个替换
<tr ng-repeat="sample in $data | filter:search ">
ngTable
指令与$data
变量一起使用,请参见example。注意
我尝试了您的随身听,并且替换解决了问题,here您的随身听的工作版本。