Ngx-datatable: Sorting doesn't work if with a custom template header

Created on 16 Jan 2017  路  11Comments  路  Source: swimlane/ngx-datatable

If a custom template is used in a header, the columns stop being sortable. If you click the header nothing happens.

That can actually be verified in the demo itself:
http://swimlane.github.io/ngx-datatable/#
If you go to templates - inline. The first column (which is the one with a custom header) is the only one that is not sortable.

EDIT: notice there was actually an old open issue with this. Maybe it has been forgotten https://github.com/swimlane/ngx-datatable/issues/233

Bug Moderate Med

Most helpful comment

How is this closed? Sorting still doesn't work!

All 11 comments

@amcdnl any suggestions how to get sorting work with custom templates?

related: https://github.com/swimlane/ngx-datatable/issues/332

I see there is no click handler for header template: https://github.com/swimlane/ngx-datatable/blob/master/src/components/header/header-cell.component.ts#L21-L34

I also see the onSort method doesnt need any arguments: https://github.com/swimlane/ngx-datatable/blob/master/src/components/header/header-cell.component.ts#L123-L132 so all i need is to somehow invote it from the datatable instance, but i cannot find it :D

edit: this worked, if anybody else looking for a solution

header-cell.component.ts template:

<template
  *ngIf="column.headerTemplate"
  [ngTemplateOutlet]="column.headerTemplate"
  [ngOutletContext]="{ 
    column: column, 
    sortDir: sortDir,
    dosort: sortHak
  }">
</template>

and in the class definition sortHak = this.onSort.bind(this);

I was trying that same approach but it wasn't working the other day. Didn't dig in too much yet though.

@tsm91 - if that works for u, then do a PR maybe i missed something

@amcdnl after the project i working on is done (very soon) ill go through my notes regarding the datatable and patch it up where needed

This is resolved in latest

How is this closed? Sorting still doesn't work!

I was able to make it work by adding ng-click="handleClick($event)" in the headerCellTemplate

For anyone else confused as to how to use a custom comparator in a template, you can pass the row data to the comparator by putting prop="" in the template, like this:



{{row.numReviewed}}/{{row.numEntries}}

Somebody can provide a sample of sortable table using ngx-datatable-column i already tried a lot and didn't find any way to do this work.

Sorting still doesn't working in client side !

Still can麓t find a way to get this working

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TakhirMamirov picture TakhirMamirov  路  3Comments

mmrath picture mmrath  路  3Comments

dinvlad picture dinvlad  路  3Comments

lautarobock picture lautarobock  路  3Comments

Matthi0uw picture Matthi0uw  路  3Comments