ngx-datatable: Re-ordering rows does not cause view to update
I’m submitting a … (check one with “x”)
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here
Current behavior If the input rows are re-ordered, the visualization of the table is not updated.
Expected behavior If the input rows are re-ordered, I would expect the view to reflect this change.
Reproduction of the problem In the following component, select the second row and click the “Up” button.
Expected behaviour: first row in table is “b”, second row in table is “a” Actual behaviour: Table does not change (first row “a”, second row “b”).
import { Component } from '@angular/core'
@Component({
selector: 'table-test',
template: `
<swui-datatable
class="material"
[rows]="rows"
[selected]="selected"
[selectionType]="'single'">
<swui-datatable-column name="Prop" prop="prop" [sortable]="false">
</swui-datatable-column>
</swui-datatable>
<button (click)="clickUp()">Up</button>
`
})
export class StartComponent {
selected :any[] = []
rows = [ { prop: 'a' }, { prop: 'b' } ]
clickUp() {
console.log(JSON.stringify(this.rows))
let ix = this.getSelectedIx()
let arr = [ ...this.rows ]
arr[ix-1] = this.rows[ix]
arr[ix] = this.rows[ix-1]
this.rows.splice(0, this.rows.length, ...arr)
console.log(JSON.stringify(this.rows))
}
getSelectedIx() {
return this.selected[0]['$$index']
}
}
What is the motivation / use case for changing the behavior? The user should be able to choose the order of a table arbitrarily.
-
Table version: 2.2.3
-
Angular version: 2.4.0
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (8 by maintainers)
Is there a workaround to force redraw?
From my point of view, this issue is still open - I do not believe that
onPushis relevant here, see above.Is there any more information I can provide?
Sure: http://plnkr.co/edit/8ieWISBXrrzwuW290QdS?p=preview
The “Switch” button switches the first two rows in the table. The view does not update. The “Add” button switches the first two rows in the table and adds a row at the bottom. The view does update.
Thanks for looking into it.