0

In angular2-datatable there's an implementation for sorting when click on the item on table head. For this we have to use DefaultSorter as:

<mfDefaultSorter [by]="sortByItem">{{ head }}</mfDefaultSorter>

the by attribute call the sortByItem method in which you can capture the event.

sortByItem(event) {
  return event._id;
}

I want to pass additional parameter with the exact event. I have tried using the ref variable but that doesn't work or you can say it doesn't fulfill what I want to achieve.

In order to see it for yourself, I have created this stackblitz: https://stackblitz.com/edit/angular2-datatable

In the above mentioned example you can check sortByWordLength method. I want to pass the exact event with additional parameter.

Additional Information:

npm: https://www.npmjs.com/package/angular2-datatable

github: https://github.com/mariuszfoltak/angular2-datatable

1 Answer 1

1

You can pass additional parameter using curried function like below.

  <mfDefaultSorter [by]="sortByWordLength('abc')">City</mfDefaultSorter>
  ...
  public sortByWordLength = (b:string) => (a: any) => {
     console.log(a);
     console.log(b);
     return a.city.length;
  }

https://stackblitz.com/edit/angular2-datatable-ldp4fg

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.