I am trying create a datatable plugin which reflect same as jQuery datatable plugin with single search box. My Data table plugin code using ngTable is not displaying any data and there there is no error on console also. Please help. Here is my code:
<html>
<head>
<title>Insert title here</title>
<script src="js/angular.min.js"></script>
<link rel="stylesheet" href="js/ng-table.min.css">
<script src="js/ng-table.min.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="dataTable">
<input type="text" ng-model="searchUser">
<table ng-table="vm.tableParams" class="table">
<tr ng-repeat="user in $data">
<td title="'Name'" sortable="'name'">
{{user.name}}</td>
<td title="'Age'" sortable="'age'">
{{user.age}}</td>
</tr>
</table>
</div>
<script type="text/javascript">
angular.module("myApp",["ngTable"]) .controller('dataTable',function(NgTableParams,$scope,$filter){
var self = this;
var data = [{name: "Moroni", age: 50},
{name: "Simon", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Christian", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27}
];
self.tableParams = new NgTableParams({ count: 5}, { counts: [5, 10, 25],dataset: data});
var usersData = []; // initial data
self.tableParams = new NgTableParams({
page: 1,
count: 5
}, {
counts : [5, 10, 25],
getData: function($defer, params) {
var searchedData = searchData();
params.total(searchedData.length);
$scope.users = searchedData.slice((params.page() - 1) * params.count(), params.page() * params.count());
$defer.resolve($scope.users);
},
$scope: { $data: {} }
});
$scope.$watch("searchUser", function () {
self.tableParams.reload();
});
var searchData = function(){
if($scope.searchUser)
return $filter('filter')(usersData,$scope.searchUser);
return usersData;
};
});
</script>
</body>
</html>