hangMan
hangMan

Reputation: 91

sort number column in ngx-datatable in ascending and descending order. Angular 2/4

I need to sort an ID number column in a ngx-datatable. I also have null values in the table, how do i get the column in ascending order and get the null in the end. It sorts from fine from the server but when i try to sort desc and back to ascending the nulls always come first. I need then to bein the end when sorting ascending order. Here are some of my codes

Template

<ngx-datatable-column prop="ID" name="ID">
     <template let-column="column" let-sort="sortFn" ngx-datatable-header-template>
       <span (click)="sort()" class="sort-fullwidth">ID</span>
     </template>
</ngx-datatable-column>

I have no clue where that sort method goes. I tried the [sorts]= " [{ prop : 'ID', dir : 'asc' ] ", [comparator] (but not sure i did it correct).

Thank you

Upvotes: 2

Views: 10093

Answers (2)

Stephen Kuehl
Stephen Kuehl

Reputation: 105

The following link describes default sorting but ilyaoverflow is right. The only line you need to add to your HTML is this:
[sorts]="[{prop: 'approvalStatus', dir: 'asc'}]"
https://github.com/swimlane/ngx-datatable/blob/master/demo/sorting/sorting-default.component.ts

Upvotes: 2

ilyaoverflow
ilyaoverflow

Reputation: 91

It will look something like this:

<ngx-datatable class='material' [columns]="columns" [rows]="rows" [columnMode]="'force'" [headerHeight]="50" [footerHeight]="50" [rowHeight]="'auto'" [limit]="100" [sortType]="'multi'" [reorderable]="true" [sorts]="[{prop: 'ID', dir: 'asc'}]">

Upvotes: 9

Related Questions