This repository has been archived by the owner on Jan 7, 2022. It is now read-only.
forked from swimlane/angular-data-table
-
Notifications
You must be signed in to change notification settings - Fork 11
Added internal paging #51
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
76d91e0
Added internal paging
981e286
Fixed formatting on paging.html
184d0da
Unit testing for internal paging, sorting
a6139a1
Merge branch 'master' into internal-paging
bensgroi 4696caf
Fixed broken DataTableController unit tests
e75443b
tweaks to fit eslint
6204a5b
One more eslint tweak
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,69 @@ | ||
import DataTableController from './DataTableController'; | ||
import TableDefaults from '../defaults'; | ||
|
||
describe('DataTableController', () => { | ||
// let $controller = null; | ||
// | ||
// beforeEach( | ||
// inject((_$controller_) => { | ||
// $controller = _$controller_; | ||
// }), | ||
// ); | ||
|
||
it('should export a function', () => { | ||
expect(DataTableController).toEqual(jasmine.any(Function)); | ||
}); | ||
let ctrl = null; | ||
let scope = null; | ||
let setController = null; | ||
|
||
beforeEach(inject(($rootScope, $filter) => { | ||
scope = $rootScope.$new(); | ||
|
||
setController = (bindings) => { | ||
bindings.options = Object.assign({}, TableDefaults, bindings.options); | ||
bindings.data = bindings.rows; | ||
|
||
ctrl = new DataTableController(scope, $filter); | ||
|
||
Object.assign(ctrl, bindings); | ||
}; | ||
})); | ||
|
||
describe('sorting', () => { | ||
|
||
beforeEach(() => { | ||
let options = { | ||
columns: [ | ||
{ prop: 'name', sort: 'asc' }, | ||
{ prop: 'age'} | ||
] | ||
}; | ||
let rows = [ | ||
{ name: 'Walter', age: 49 }, | ||
{ name: 'Dude', age: 45 }, | ||
{ name: 'Donnie', age: 46 }, | ||
{ name: 'Maude', age: 48 } | ||
]; | ||
|
||
setController({ | ||
options: options, | ||
rows: rows | ||
}); | ||
|
||
ctrl.$onInit(); | ||
}); | ||
|
||
it('should be sorted', () => { | ||
ctrl.onSorted(); | ||
|
||
let sortOrder = ctrl.rows[0].name < ctrl.rows[1].name; | ||
|
||
expect(sortOrder).toBe(true); | ||
}); | ||
|
||
it('should re-sort', () => { | ||
ctrl.onSorted(); | ||
|
||
let sortedAscending = ctrl.rows[0].name < ctrl.rows[1].name; | ||
|
||
expect(sortedAscending).toBe(true); | ||
|
||
ctrl.options.columns[0].sort = 'desc'; | ||
ctrl.onSorted(); | ||
|
||
describe('', () => { | ||
sortedAscending = ctrl.rows[0].name < ctrl.rows[1].name; | ||
|
||
expect(sortedAscending).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,19 @@ export default class BodyController { | |
} | ||
} | ||
|
||
/** | ||
* @description Constructs the rows for the page, assuming we're using internal paging. | ||
*/ | ||
buildInternalPage() { | ||
let i; | ||
|
||
this.tempRows.splice(0, this.tempRows.length); | ||
|
||
for (i = 0; i < this.options.paging.size; i += 1) { | ||
this.tempRows[i] = this.rows[(this.options.paging.offset * this.options.paging.size) + i]; | ||
} | ||
} | ||
|
||
setConditionalWatches() { | ||
for (let i = this.watchListeners.length - 1; i >= 0; i -= 1) { | ||
this.watchListeners[i](); | ||
|
@@ -82,7 +95,7 @@ export default class BodyController { | |
(this.options.scrollbarV || | ||
(!this.options.scrollbarV && | ||
this.options.paging && | ||
this.options.paging.externalPaging))) { | ||
this.options.paging.size))) { | ||
let sized = false; | ||
|
||
this.watchListeners.push(this.$scope.$watch('body.options.paging.size', (newVal, oldVal) => { | ||
|
@@ -99,10 +112,16 @@ export default class BodyController { | |
|
||
this.watchListeners.push(this.$scope.$watch('body.options.paging.offset', (newVal) => { | ||
if (this.options.paging.size) { | ||
this.onPage({ | ||
offset: newVal, | ||
size: this.options.paging.size, | ||
}); | ||
if (!this.options.paging.externalPaging) { | ||
this.buildInternalPage(); | ||
} | ||
|
||
if (this.onPage) { | ||
this.onPage({ | ||
offset: newVal, | ||
size: this.options.paging.size, | ||
}); | ||
} | ||
} | ||
})); | ||
} | ||
|
@@ -137,14 +156,19 @@ export default class BodyController { | |
} | ||
|
||
if (this.options.paging.externalPaging) { | ||
// We're using external paging | ||
const idxs = this.getFirstLastIndexes(); | ||
let idx = idxs.first; | ||
|
||
this.tempRows.splice(0, this.tempRows.length); | ||
while (idx < idxs.last) { | ||
this.tempRows.push(rows[idx += 1]); | ||
} | ||
} else if (this.options.paging.size) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this is nested in a this.options.paging.size already, which would prevent the next else statement from ever firing. Looks safe to remove the if condition and the else below it, but you may know more about this area than me now :) That being said - do we know the relation of the externalPaging logic to all of that paging that happens in virtual paging? |
||
// We're using internal paging | ||
this.buildInternalPage(); | ||
} else { | ||
// No paging | ||
this.tempRows.splice(0, this.tempRows.length); | ||
this.tempRows.push(...rows); | ||
} | ||
|
@@ -439,7 +463,9 @@ export default class BodyController { | |
rowIndex += 1; | ||
} | ||
|
||
this.options.internal.styleTranslator.update(this.tempRows); | ||
if (this.options.internal && this.options.internal.styleTranslator) { | ||
this.options.internal.styleTranslator.update(this.tempRows); | ||
} | ||
|
||
return this.tempRows; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like we could use a global 'sortable'!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Added issue #53