Search code examples
angularcalculated-columnsngx-datatableng-template

ngx-datatable - Any way to preserve column order after a user repositions them?


Users like the out of the box ability to drag columns around to reorder them in the ngx-datatable. However, they want me to preserve the order after they get them exactly like they like them. I understand how to define the columns in the TS file. But I'm not sure how to capture the changes to the columns when the user drags them around in the UI. Is this possible?

To be clear, if my original column structure is [A, B, C] and the user manually drags column B to the left and now the order is [B, A, C], how to I get notified in code that the reorder happened so I can save the new order of [B, A, C] somewhere?


Solution

  • They have an event emitter notifying when a column has been reordered https://github.com/swimlane/ngx-datatable/blob/master/projects/swimlane/ngx-datatable/src/lib/components/datatable.component.ts

    @Output() reorder: EventEmitter<any> = new EventEmitter();
    

    Docs: https://swimlane.gitbook.io/ngx-datatable/api/table/outputs#reorder