Issue re-ordering columns when some columns are hidden
[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35
Plunkr Case (Bug Reports) Please demonstrate your case at stackblitz by using the issue template below. Issues without a test case have much less possibility to be reviewd in detail and assisted.
https://nbwiamqn.github.stackblitz.io
Current behavior Hiding columns based on a value in the columnDefinitions array seems to work well. The problem is when you attempt to add column reorder support, in which case trying to reorder the columns mis-behaves. The headers don't reorder, but it appears that the body column elements may actually move. hard to tell for sure. Update: It seems as though if the last column in the data is hidden, there is no issue, but if any column inside middle of the data is, it mis-behaves.
Expected behavior Re-ordering columns should work as expected even when certain columns have been hidden.
Minimal reproduction of the problem with instructions See demo linked above. First table works and re-orders. Second table, which has a hidden column, does not re-order properly.
What is the motivation / use case for changing the behavior? Correct functionality
Please tell us about your environment: Windows, Chrome, VSCode, ng build (webpack)
-
Angular version: 6.1
-
PrimeNG version: 6.1.2
-
Browser: [Chrome 62]
-
Language: [TypeScript 2.7.2]
-
Node (for AoT issues):
node --version=
8.9.4
Hello Is It solved?
I'm unable to replicate with the latest PrimeNG. If the issue still persists wit|h the new version please create a new issue with our stackblitz template.
Hi @cagataycivici Here is an example where you can reproduce this issue - https://stackblitz.com/edit/primeng-tablereorder-demo-lnn1fz?file=src%2Fapp%2Fapp.component.html
Steps to reproduce:
- Hide "Category" column by clicking on the checkbox
- Try to reorder the last column
From my understanding, the issue can be in this method:
onColumnDrop(event, dropColumn) {
event.preventDefault();
if (this.draggedColumn) {
let dragIndex = DomHandler.indexWithinGroup(this.draggedColumn, 'preorderablecolumn');
let dropIndex = DomHandler.indexWithinGroup(dropColumn, 'preorderablecolumn');
let allowDrop = (dragIndex != dropIndex);
if (allowDrop && ((dropIndex - dragIndex == 1 && this.dropPosition === -1) || (dragIndex - dropIndex == 1 && this.dropPosition === 1))) {
allowDrop = false;
}
if (allowDrop && ((dropIndex < dragIndex && this.dropPosition === 1))) {
dropIndex = dropIndex + 1;
}
if (allowDrop && ((dropIndex > dragIndex && this.dropPosition === -1))) {
dropIndex = dropIndex - 1;
}
if (allowDrop) {
ObjectUtils.reorderArray(this.columns, dragIndex, dropIndex);
this.onColReorder.emit({
dragIndex: dragIndex,
dropIndex: dropIndex,
columns: this.columns
});
if (this.isStateful()) {
this.zone.runOutsideAngular(() => {
setTimeout(() => {
this.saveState();
});
});
}
}
this.reorderIndicatorUpViewChild.nativeElement.style.display = 'none';
this.reorderIndicatorDownViewChild.nativeElement.style.display = 'none';
this.draggedColumn.draggable = false;
this.draggedColumn = null;
this.dropPosition = null;
}
}
let dragIndex = DomHandler.indexWithinGroup(this.draggedColumn, 'preorderablecolumn');
let dropIndex = DomHandler.indexWithinGroup(dropColumn, 'preorderablecolumn');
dragIndex and dropIndex are taking from DOM and reordering is made on columns object
ObjectUtils.reorderArray(this.columns, dragIndex, dropIndex);
And in case if columns object has hidden items, indexes can be incorrect.