ngx-datatable: Sorting with custom template - click handler doesn't seem to work
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, post on Stackoverflow or Gitter
Current behavior
Looks a lot like https://github.com/swimlane/ngx-datatable/issues/431
custom column template with server side pagination
on sort function is
(sort)="onPageSorted($event)"
and column is defined as
<ngx-datatable-column name="ID" [resizeable]="false" [sortable]="true" [flexGrow]="1">
<ng-template let-column="column" ngx-datatable-header-template>
{{column.name}}
</ng-template>
<ng-template let-value="value" ngx-datatable-cell-template>
<strong>{{value}}</strong>
</ng-template>
</ngx-datatable-column>
Expected behavior
on click on the column header will trigger the event
Reproduction of the problem
What is the motivation / use case for changing the behavior?
Please tell us about your environment:
- Table version: 0.8.x
9.3.0
- Angular version: 2.0.x
4.1.3
- Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
all
- Language: [all | TypeScript X.X | ES6/7 | ES5] TypeScript 2.3.4
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 11
- Comments: 19
True…but if you do this, it will work: https://github.com/swimlane/ngx-datatable/issues/681#issuecomment-297386597
In your case
Use this
this works now. even if you do not provide the implementation for the sort function.
I also did server side sorting. You need to set the function on the ngx-datatable like (sort)=“onSort($event)” To extend the above example from my code it looks like this:
This icludes server side sorting, server side pagination, selection boxes, custom header and column templates with custom footer that allows the user to change the page size.
Hope that it helps you.
I am also not able to see direction indicator with custom header.
Yeah, I noticed let-sortDir is undefined now as well…this is not good 😦
@kedar700 Thank you your suggestion works for my scenario. Looking through the docs I didn’t see any examples of how to setup sorting when using custom templates like this. Or did I miss it?
But how do you define the sortFn in ts code? This way, the built-in sorting function runs. I need to call a custom function to call server-side sorting.
Shortly after posting my comment above I was able to find a workaround using
let-sortDir="sortDir":Produces:
If I wanted icons specifically I could do something like this: