Skip to content

Commit 02391fe

Browse files
committed
publish new version
1 parent c50bde5 commit 02391fe

10 files changed

+111
-39
lines changed

bower.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
2-
"name": "angular-smart-table",
3-
"version": "2.1.0",
4-
"homepage": "https://github.com/lorenzofox3/Smart-Table",
5-
"authors": [
6-
"lorenzofox3 <[email protected]>"
7-
],
8-
"description": "table module for angular",
9-
"main": "dist/smart-table.js",
10-
"keywords": [
11-
"smart-table",
12-
"angular",
13-
"table"
14-
],
15-
"license": "MIT",
16-
"ignore": [
17-
"node_modules",
18-
"bower_components",
19-
"test",
20-
"tests"
21-
],
22-
"dependencies": {
23-
"angular": "^1.0.0"
24-
},
25-
"devDependencies": {
26-
"angular-mocks": "^1.0.0",
27-
"jquery": "^2.0.0"
28-
}
2+
"name": "angular-smart-table",
3+
"version": "2.1.1",
4+
"homepage": "https://github.com/lorenzofox3/Smart-Table",
5+
"authors": [
6+
"lorenzofox3 <[email protected]>"
7+
],
8+
"description": "table module for angular",
9+
"main": "dist/smart-table.js",
10+
"keywords": [
11+
"smart-table",
12+
"angular",
13+
"table"
14+
],
15+
"license": "MIT",
16+
"ignore": [
17+
"node_modules",
18+
"bower_components",
19+
"test",
20+
"tests"
21+
],
22+
"dependencies": {
23+
"angular": "^1.0.0"
24+
},
25+
"devDependencies": {
26+
"angular-mocks": "^1.0.0",
27+
"jquery": "^2.0.0"
28+
}
2929
}

changeLog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,10 @@ function(tableState, tableController){
139139
* support nested search (thanks to @jansabbe)
140140
* fix #254
141141
* fix wrong path to default config for stSkipNatural (@phuvo)
142-
* fix #406
142+
* fix #406
143+
144+
## version 2.1.1
145+
146+
* support commonjs
147+
* add totalItemCount on tableState (@eirikbell)
148+

dist/smart-table.js

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/smart-table.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-smart-table",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

src/stPagination.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ng.module('smart-table')
2828
var end;
2929
var i;
3030
var prevPage = scope.currentPage;
31+
scope.totalItemCount = paginationState.totalItemCount;
3132
scope.currentPage = Math.floor(paginationState.start / paginationState.number) + 1;
3233

3334
start = Math.max(start, scope.currentPage - Math.abs(Math.floor(scope.stDisplayedPages / 2)));

src/stTable.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ ng.module('smart-table')
1111
sort: {},
1212
search: {},
1313
pagination: {
14-
start: 0
14+
start: 0,
15+
totalItemCount: 0
1516
}
1617
};
1718
var filtered;
@@ -114,6 +115,7 @@ ng.module('smart-table')
114115
if (tableState.sort.predicate) {
115116
filtered = orderBy(filtered, tableState.sort.predicate, tableState.sort.reverse);
116117
}
118+
pagination.totalItemCount = filtered.length;
117119
if (pagination.number !== undefined) {
118120
pagination.numberOfPages = filtered.length > 0 ? Math.ceil(filtered.length / pagination.number) : 1;
119121
pagination.start = pagination.start >= filtered.length ? (pagination.numberOfPages - 1) * pagination.number : pagination.start;

test/spec/stPagination.spec.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('stPagination directive', function () {
1919
var tableState = {
2020
sort: {},
2121
search: {},
22-
pagination: {start: 0}
22+
pagination: {start: 0, totalItemCount: 0}
2323
};
2424
var compile;
2525

@@ -380,6 +380,36 @@ describe('stPagination directive', function () {
380380
expect(pages.length).toBe(0);
381381
});
382382

383+
describe('with extended template', function () {
384+
var templateCache;
385+
beforeEach(inject(function ($templateCache) {
386+
templateCache = $templateCache;
387+
}));
388+
389+
it('should save totalItemCount from paginationState on scope', function () {
390+
templateCache.put('custom_template.html', '<nav ng-if="pages.length >= 2"><ul class="pagination">' +
391+
'<li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a ng-click="selectPage(page)">{{page}}</a></li>' +
392+
'</ul>' +
393+
'<span>Showing {{(currentPage-1)*stItemsByPage+1}}-{{(currentPage)*stItemsByPage > totalItemCount ? totalItemCount : (currentPage)*stItemsByPage}} of {{totalItemCount}}</span>' +
394+
'</nav>');
395+
396+
var template = '<table st-table="rowCollection"><tfoot><tr><td id="pagination" st-pagination="" st-template="custom_template.html" st-items-by-page="2"></td></tr></tfoot></table>';
397+
element = compile(template)(rootScope);
398+
399+
rootScope.$apply();
400+
401+
tableState.pagination = {
402+
start: 3,
403+
numberOfPages: 3,
404+
number: 2,
405+
totalItemCount: 5
406+
};
407+
408+
rootScope.$apply();
409+
410+
expect(element.find('SPAN')[0].innerHTML).toBe('Showing 3-4 of 5');
411+
});
412+
});
383413
});
384414

385415
describe('select page', function () {
@@ -485,7 +515,7 @@ describe('stPagination directive', function () {
485515
expect(rootScope.onPageChange).toHaveBeenCalledWith(3);
486516
expect(rootScope.onPageChange.calls.length).toBe(1);
487517

488-
tableState.pagination.numberOfPages=5;
518+
tableState.pagination.numberOfPages = 5;
489519

490520
rootScope.$apply();
491521
pages = getPages();

test/spec/stPipe.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ describe('stPipe directive', function () {
4141
$timeout.flush();
4242

4343
expect(firstArg).toEqual({
44-
sort: {predicate: 'name', reverse: false}, search: {}, pagination: {start: 0}
44+
sort: {predicate: 'name', reverse: false}, search: {}, pagination: {start: 0, totalItemCount: 0}
4545
});
4646

4747
expect(secondArg.tableState()).toEqual({
48-
sort: {predicate: 'name', reverse: false}, search: {}, pagination: {start: 0}
48+
sort: {predicate: 'name', reverse: false}, search: {}, pagination: {start: 0, totalItemCount: 0}
4949
});
5050
}));
5151
});

test/spec/stTable.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ describe('st table Controller', function () {
2828

2929
}));
3030

31+
describe('init', function(){
32+
it('should contain default tableState', function(){
33+
var defaultTableState = {
34+
sort: {},
35+
search: {},
36+
pagination: {
37+
start: 0,
38+
totalItemCount: 0
39+
}
40+
};
41+
42+
var tableState = ctrl.tableState();
43+
expect(tableState).toEqual(defaultTableState);
44+
});
45+
});
46+
3147
describe('sort', function () {
3248
it('should sort the data', function () {
3349
ctrl.sortBy('firstname');
@@ -191,6 +207,20 @@ describe('st table Controller', function () {
191207
});
192208

193209
describe('pipe', function () {
210+
it('should set totalItemCount on tableState pagination', function(){
211+
var expectedLength = 5;
212+
ctrl.pipe();
213+
expect(scope.data.length).toBe(expectedLength);
214+
expect(ctrl.tableState().pagination.totalItemCount).toBe(expectedLength);
215+
});
216+
217+
it('should set totalItemCount as size of filtered array', function(){
218+
var expectedLength = 3;
219+
ctrl.search('re', 'name');
220+
expect(scope.data.length).toBe(expectedLength);
221+
expect(ctrl.tableState().pagination.totalItemCount).toBe(expectedLength);
222+
});
223+
194224
it('should remembered the last slice length but start back to zero when sorting', function () {
195225
ctrl.slice(1, 2);
196226
expect(scope.data.length).toBe(2);

0 commit comments

Comments
 (0)