0

Im ordering a table by room number, most rooms follow numeric value's in order such as 1,2,3,4 etc, however some room are 12A, 12B etc and the ordering takes the numbers into consideration before the lettersenter image description here

I'm using an ngx-datatable and filtering using -

<ngx-datatable    
  [sorts]="[{prop: 'locationUnit', dir: 'asc'}]"

I would like it to filter by numbers with the letters, then the higher numbers and letters. In the example above it should be 1A, 4, 5, 12A, 12C. Thanks

DZF
  • 137
  • 11
  • What is your question? – Alireza Ahmadi Aug 16 '21 at 15:26
  • I have a solution for initialize time but when you click on each header the default sort will be executed! :) – Alireza Ahmadi Aug 16 '21 at 16:15
  • @jcalz I think OP's question is about how to apply custom sort in `ngx-datatable` I know the sort method is answered before but `How to apply in ngx-datatable`?? – Alireza Ahmadi Aug 16 '21 at 16:17
  • in ngx-table you can define a comparator in the columns: `{ key: 'room', title: "Room",comparator: this.roomComparator.bind(this) }`, the function roomComparator can be like: `roomComparator(propA, propB){ const a='0000'+propA.slice(-4); const b='0000'+propB.slice(-4); return a>b?1:a – Eliseo Aug 16 '21 at 17:33
  • see a stackblitz example:https://stackblitz.com/edit/ngx-datatable-angular-bo2ntf?file=src%2Fapp%2Fbasic%2Fbasic.component.ts – Eliseo Aug 16 '21 at 17:41

0 Answers0