svelte-simple-datatables
svelte-simple-datatables copied to clipboard
Filter function does not have access to global/outer scope
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)
ugly workaround:
set the functions to window.functionName or call em that way.