svelte-simple-datatables icon indicating copy to clipboard operation
svelte-simple-datatables copied to clipboard

Filter function does not have access to global/outer scope

Open jon-v2 opened this issue 2 years ago • 1 comments

Discussed in https://github.com/vincjo/svelte-simple-datatables/discussions/70

Originally posted by submergeme September 15, 2022 From my understanding, you can set the data-key property to equal a function for custom filtering. This is great except you cant use a predefined function within your component i.e:

const convertDate = (date) => { return moment(date).utc().format("MMM Do YYYY"); }

...

<th data-key={(row) => convertDate(row.date)}>Date</th>

this will throw an exception saying convertDate does not exist. Please assist.

Edit: that being said, you can't reference "moment" directly either (as it will throw an exception saying moment doesn't exist)

jon-v2 avatar Sep 15 '22 22:09 jon-v2

ugly workaround:

set the functions to window.functionName or call em that way.

michapixel avatar Sep 27 '22 10:09 michapixel