angularjs分页,排序,过滤表

时间:2016-05-21 02:55:31

标签: javascript arrays angularjs pagination

我在以下链接中找到了这个令人惊讶的可用示例:http://ng-table.com/#/loading/demo-managed-array

它可以在表格中执行以下所有操作:filter,sort,pagination

我似乎没有得到如何在表中的js中集成定义的数组。代码未显示其示例中定义的任何数组。

我想在其中集成以下数组:

   $scope.detailsArray=[{'name':'Visited With','clicker':'visitedTab','date':'08-05-2016'},
 {'name':'Time (24 Hour)','clicker':'timeTab','date':'04-05-2016'}, 
 {'name':'Sampling','clicker':'samplingTab','date':'01-05-2016'}, 
 {'name':'Prescription Audit','clicker':'prescriptionTab','date':'12-05-2016'},
 {'name':'Brand Reminders','clicker':'bRemindersTab','date':'22-05-2016'},
 {'name':'Call Type','clicker':'calltypeTab','date':'14-05-2016'}];

我也想在日期对列进行排序。

我试图整合。他们允许在代码笔上编辑。但我没能整合它。如果有人设法整合它,请提供codetoo。任何angularjs专家可以帮忙吗?将非常有帮助!提前谢谢

1 个答案:

答案 0 :(得分:0)

我写这个答案是因为评论有限!

我做到了:

js:

(function() {
 "use strict";

  var app = angular.module("myApp", ["ngTable", "ngTableDemos"]);

   app.controller("demoController", demoController);
  demoController.$inject = ["NgTableParams", "ngTableSimpleList"];

  var dataset=[{'name':'Visited With','clicker':'visitedTab','date':'08-05-2016'},
{'name':'Time (24 Hour)','clicker':'timeTab','date':'04-05-2016'}, 
{'name':'Sampling','clicker':'samplingTab','date':'01-05-2011'}, 
{'name':'Prescription Audit','clicker':'prescriptionTab','date':'12-05-2016'},
{'name':'Brand Reminders','clicker':'bRemindersTab','date':'22-05-2016'},
{'name':'Call Type','clicker':'calltypeTab','date':'14-05-2015'}];
 var tp = new NgTableParams({}, { dataset: dataset });

function demoController(NgTableParams, simpleList) {
   var self = this;
   self.tableParams = new NgTableParams({}, {
    dataset: dataset
   });
 }
})();

HTML:

<div ng-app="myApp">
  <div ng-controller="demoController as demo">
    <h2 class="page-header">Loading data - managed array</h2>
    <div class="bs-callout bs-callout-info">
      <h4>Overview</h4>
      <p>When you have the <em>entire</em> dataset available in-memory you can hand this to <code>NgTableParams</code> to manage the filtering, sorting and paging of that array</p>
    </div>
    <table ng-table="demo.tableParams" class="table table-condensed table-bordered table-striped">
      <tr ng-repeat="row in $data">
        <td data-title="'Name'" filter="{name: 'text'}" sortable="'name'">{{row.name}}</td>
        <td data-title="'clicker'" filter="{clicker: 'text'}" sortable="'clicker'">{{row.clicker}}</td>
        <td data-title="'date'" filter="{date: 'date'}" sortable="'date'">{{row.date}}</td>
      </tr>
    </table>
  </div>
</div>

这是笔:http://codepen.io/anon/pen/WwVQeP?editors=1010

现在唯一的问题是对日期进行排序!谁能找到解决方案?