Skip to content

Commit

Permalink
Merge bd797ea into 107138b
Browse files Browse the repository at this point in the history
  • Loading branch information
leonar15 committed Dec 20, 2013
2 parents 107138b + bd797ea commit 068225c
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 8 deletions.
74 changes: 74 additions & 0 deletions examples/demo27.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">

<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<!--[if lt IE 9]>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<![endif]-->
<script src="js/angular.min.js"></script>
<script src="../ng-table.src.js"></script>
<link rel="stylesheet" href="../ng-table.css">
</head>
<body ng-app="main">
<h1>Table with data passed at init</h1>

<div ng-controller="DemoCtrl">

<p><strong>Page:</strong> {{tableParams.page()}}
<p><strong>Count per page:</strong> {{tableParams.count()}}


<table ng-table="tableParams" class="table ng-table-responsive">
<tr ng-repeat="user in $data">
<td data-title="'Name'">
{{user.name}}
</td>
<td data-title="'Age'">
{{user.age}}
</td>
</tr>
</table>

<script>
var app = angular.module('main', ['ngTable']).
controller('DemoCtrl', function($scope, ngTableParams) {
var data = [{name: "Moroni", age: 50},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34},
{name: "Tiancum", age: 43},
{name: "Jacob", age: 27},
{name: "Nephi", age: 29},
{name: "Enos", age: 34}];

$scope.tableParams = new ngTableParams({
page: 1, // show first page
count: 10 // count per page
}, {
data: data
});
})
</script>

</div>


</body>
</html>
3 changes: 2 additions & 1 deletion ng-table.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ng-table.map

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions ng-table.src.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ app.factory('ngTableParams', ['$q', '$log', function ($q, $log) {
*/
this.settings = function (newSettings) {
if (angular.isDefined(newSettings)) {
if (angular.isArray(newSettings.data)) {
//auto-set the total from passed in data
newSettings.total = newSettings.data.length;
}
settings = angular.extend(settings, newSettings);
$log.debug && $log.debug('ngTable: set settings', params);
$log.debug && $log.debug('ngTable: set settings', settings);
return this;
}
return settings;
Expand Down Expand Up @@ -236,7 +240,11 @@ app.factory('ngTableParams', ['$q', '$log', function ($q, $log) {
* @param {Object} params New parameters
*/
this.getData = function ($defer, params) {
$defer.resolve([]);
if (angular.isArray(this.data) && angular.isObject(params)) {
$defer.resolve(this.data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
} else {
$defer.resolve([]);
}
};

/**
Expand Down Expand Up @@ -415,6 +423,7 @@ app.factory('ngTableParams', ['$q', '$log', function ($q, $log) {
var settings = {
$scope: null, // set by ngTable controller
$loading: false,
data: null, //allows data to be set when table is initialized
total: 0,
counts: [10, 25, 50, 100],
getGroups: this.getGroups,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-requirejs": "~0.4.0",
"grunt-contrib-uglify": "~0.2.1",
"grunt": "~0.4.1",
"grunt": "~0.4.2",
"grunt-contrib-less": "~0.5.2",
"grunt-contrib-cssmin": "~0.6.1",
"karma": "~0.10",
Expand All @@ -27,7 +27,8 @@
"karma-firefox-launcher": "*",
"karma-ng-html2js-preprocessor": "*",
"coveralls": "",
"karma-coverage": "~0.1.0"
"karma-coverage": "~0.1.0",
"grunt-coffee-build": "~1.4.12"
},
"scripts": {
"test": "karma start --single-run --no-auto-watch"
Expand Down
13 changes: 11 additions & 2 deletions src/scripts/03-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ app.factory('ngTableParams', ['$q', '$log', function ($q, $log) {
*/
this.settings = function (newSettings) {
if (angular.isDefined(newSettings)) {
if (angular.isArray(newSettings.data)) {
//auto-set the total from passed in data
newSettings.total = newSettings.data.length;
}
settings = angular.extend(settings, newSettings);
$log.debug && $log.debug('ngTable: set settings', params);
$log.debug && $log.debug('ngTable: set settings', settings);
return this;
}
return settings;
Expand Down Expand Up @@ -190,7 +194,11 @@ app.factory('ngTableParams', ['$q', '$log', function ($q, $log) {
* @param {Object} params New parameters
*/
this.getData = function ($defer, params) {
$defer.resolve([]);
if (angular.isArray(this.data) && angular.isObject(params)) {
$defer.resolve(this.data.slice((params.page() - 1) * params.count(), params.page() * params.count()));
} else {
$defer.resolve([]);
}
};

/**
Expand Down Expand Up @@ -369,6 +377,7 @@ app.factory('ngTableParams', ['$q', '$log', function ($q, $log) {
var settings = {
$scope: null, // set by ngTable controller
$loading: false,
data: null, //allows data to be set when table is initialized
total: 0,
counts: [10, 25, 50, 100],
getGroups: this.getGroups,
Expand Down
2 changes: 2 additions & 0 deletions test/tableParamsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ describe('ngTableParams', function () {
expect(params.settings()).toEqual({
$scope: null,
$loading: false,
data: null,
total: 0,
counts: [10, 25, 50, 100],
getData: params.getData,
Expand All @@ -159,6 +160,7 @@ describe('ngTableParams', function () {
expect(params.settings()).toEqual({
$scope: null,
$loading: false,
data: null,
total: 100,
counts: [10, 25, 50, 100],
getData: params.getData,
Expand Down

0 comments on commit 068225c

Please sign in to comment.