简体   繁体   中英

angularjs pagination, sort, filter table

i found this amaing ngtable example on the following link : http://ng-table.com/#/loading/demo-managed-array

it can do all of the following in the table: filter,sort,pagination

i don't seem to get how to integrate an defined array in js in the table. The code does not show any array defined in their example.

i want to integrate the following array in it:

   $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'}];

also i wanted to sort the column on date.

i had tried to integrate . they allow to edit on code pen. but i failed to integrate it. if anyone manages to integrate it , please provide the codetoo. any angularjs expert that can help? will be very helpful!thank you in advance

im writing it as an answer since comment is limited!

i made it work:

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>

here is the pen: http://codepen.io/anon/pen/WwVQeP?editors=1010

Now the only issue is with sorting of the date! can anyone find a solution?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM