从分组数据中过滤后,Ng表未进行过滤或排序

时间:2014-10-15 21:24:29

标签: javascript angularjs ngtable

我正在学习使用ng-table指令的angular.js和new。我正在对我的数据进行分组,然后使用ng-table显示它们。我能够查看过滤后的数据,但我无法进行排序或过滤。有人可以帮我这个。这是plunker代码。谢谢!

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()));
                                }
                            });




                        };

1 个答案:

答案 0 :(得分:2)

<tr ng-repeat="sample in myCurrentSample | filter:search ">

首先你需要用这个替换

 <tr ng-repeat="sample in $data | filter:search ">

使用ngTable变量的$data指令,看example

注意

我尝试了你的插件,并且替换解决了问题,here你的插件的工作版本。