This repository has been archived by the owner on Dec 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
dynamic grouping/tree fix #257
Open
jonshaffer
wants to merge
2
commits into
swimlane:master
Choose a base branch
from
jonshaffer:swimlane-group-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+96
−39
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,74 +12,112 @@ export class BodyController{ | |
constructor($scope, $timeout){ | ||
this.$scope = $scope; | ||
this.tempRows = []; | ||
this.watchListeners = []; | ||
|
||
this.setTreeAndGroupColumns(); | ||
this.setConditionalWatches(); | ||
|
||
$scope.$watch('body.options.columns', (newVal, oldVal) => { | ||
if (newVal) { | ||
const origTreeColumn = this.treeColumn, | ||
origGroupColumn = this.groupColumn; | ||
|
||
this.setTreeAndGroupColumns(); | ||
|
||
this.setConditionalWatches(); | ||
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. this might be more accurate be on a watch for options.scrollbarV && options.paging.externalPaging |
||
|
||
if (origGroupColumn !== this.treeColumn || origGroupColumn !== this.groupColumn) { | ||
this.rowsUpdated(this.rows); | ||
|
||
if (this.treeColumn) { | ||
this.refreshTree(); | ||
} else if (this.groupColumn) { | ||
this.refreshGroups(); | ||
} | ||
} | ||
} | ||
}, true); | ||
|
||
$scope.$watchCollection('body.rows', this.rowsUpdated.bind(this)); | ||
} | ||
|
||
setTreeAndGroupColumns() { | ||
this.treeColumn = this.options.columns.find((c) => { | ||
return c.isTreeColumn; | ||
}); | ||
|
||
this.groupColumn = this.options.columns.find((c) => { | ||
return c.group; | ||
}); | ||
if (!this.treeColumn) { | ||
this.groupColumn = this.options.columns.find((c) => { | ||
return c.group; | ||
}); | ||
} | ||
} | ||
|
||
$scope.$watchCollection('body.rows', this.rowsUpdated.bind(this)); | ||
setConditionalWatches(){ | ||
this.watchListeners.map((watchListener) => ( | ||
watchListener() | ||
)); | ||
|
||
if(this.options.scrollbarV || (!this.options.scrollbarV && this.options.paging.externalPaging)){ | ||
if (this.options.scrollbarV || (!this.options.scrollbarV && this.options.paging.externalPaging)) { | ||
var sized = false; | ||
$scope.$watch('body.options.paging.size', (newVal, oldVal) => { | ||
if(!sized || newVal > oldVal){ | ||
|
||
this.watchListeners.push(this.$scope.$watch('body.options.paging.size', (newVal, oldVal) => { | ||
if (!sized || newVal > oldVal) { | ||
this.getRows(); | ||
sized = true; | ||
} | ||
}); | ||
})); | ||
|
||
$scope.$watch('body.options.paging.count', (count) => { | ||
this.watchListeners.push(this.$scope.$watch('body.options.paging.count', (count) => { | ||
this.count = count; | ||
this.updatePage(); | ||
}); | ||
})); | ||
|
||
$scope.$watch('body.options.paging.offset', (newVal) => { | ||
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 | ||
}); | ||
} | ||
}); | ||
})); | ||
} | ||
} | ||
|
||
rowsUpdated(newVal, oldVal){ | ||
if(newVal) { | ||
if(!this.options.paging.externalPaging){ | ||
if (!newVal) { | ||
this.getRows(true); | ||
} else { | ||
if (!this.options.paging.externalPaging) { | ||
this.options.paging.count = newVal.length; | ||
} | ||
|
||
this.count = this.options.paging.count; | ||
|
||
if(this.treeColumn || this.groupColumn){ | ||
if (this.treeColumn || this.groupColumn) { | ||
this.buildRowsByGroup(); | ||
} | ||
|
||
if(this.options.scrollbarV){ | ||
if (this.options.scrollbarV) { | ||
let refresh = newVal && oldVal && (newVal.length === oldVal.length | ||
|| newVal.length < oldVal.length); | ||
|
||
this.getRows(refresh); | ||
} else { | ||
let rows = this.rows; | ||
|
||
if(this.treeColumn){ | ||
if (this.treeColumn) { | ||
rows = this.buildTree(); | ||
} else if(this.groupColumn){ | ||
} else if (this.groupColumn) { | ||
rows = this.buildGroups(); | ||
} | ||
|
||
if(this.options.paging.externalPaging){ | ||
if (this.options.paging.externalPaging) { | ||
let idxs = this.getFirstLastIndexes(), | ||
idx = idxs.first; | ||
|
||
this.tempRows.splice(0, this.tempRows.length); | ||
while(idx < idxs.last){ | ||
while (idx < idxs.last) { | ||
this.tempRows.push(rows[idx++]) | ||
} | ||
} else { | ||
|
@@ -478,6 +516,16 @@ export class BodyController{ | |
return children !== undefined || (children && !children.length); | ||
} | ||
|
||
refreshTree(){ | ||
if(this.options.scrollbarV){ | ||
this.getRows(true); | ||
} else { | ||
var values = this.buildTree(); | ||
this.tempRows.splice(0, this.tempRows.length); | ||
this.tempRows.push(...values); | ||
} | ||
} | ||
|
||
/** | ||
* Tree toggle event from a cell | ||
* @param {row model} | ||
|
@@ -487,18 +535,22 @@ export class BodyController{ | |
var val = row[this.treeColumn.prop]; | ||
this.expanded[val] = !this.expanded[val]; | ||
|
||
this.refreshTree(); | ||
|
||
this.onTreeToggle({ | ||
row: row, | ||
cell: cell | ||
}); | ||
} | ||
|
||
refreshGroups(){ | ||
if(this.options.scrollbarV){ | ||
this.getRows(true); | ||
} else { | ||
var values = this.buildTree(); | ||
var values = this.buildGroups(); | ||
this.tempRows.splice(0, this.tempRows.length); | ||
this.tempRows.push(...values); | ||
} | ||
|
||
this.onTreeToggle({ | ||
row: row, | ||
cell: cell | ||
}); | ||
} | ||
|
||
/** | ||
|
@@ -508,12 +560,6 @@ export class BodyController{ | |
onGroupToggle(row){ | ||
this.expanded[row.name] = !this.expanded[row.name]; | ||
|
||
if(this.options.scrollbarV){ | ||
this.getRows(true); | ||
} else { | ||
var values = this.buildGroups(); | ||
this.tempRows.splice(0, this.tempRows.length); | ||
this.tempRows.push(...values); | ||
} | ||
this.refreshGroups(); | ||
} | ||
} |
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.
can remove $timeout here && on doc