Hi,
Working for free for a basket-ball club, I have a table populated from a 'match' collection through dataset1. On the table headers are buttons which allow to sort the table on various columns. Above the table is a dropdown where I can choose the season (for ex. : 2018-2019)
At page opening, the table populates well through the dataset, and the sorting buttons work fine.
But if a season is chosen from the dropdown, the table re-populates well but the sorting buttons don't work any longer.
Here is a screenshot of the table :
and here is the code :
Adapting from this post : https://www.wix.com/corvid/forum/community-discussion/pass-results-from-query-into-a-dataset-filter , I tried adding this code after line 34 :
const txlist = tableRows.map(item => item);
$w('#dataset1').setFilter(wixData.filter(txlist)
.gt('dateHeure', lowerDate)
.lt('dateHeure', upperDate)
but it does not work better (though console.log(txlist) shows a list of all the records and their content).
So I wonder if the issue resides in this added code or in a misconception/misunderstanding of something else...
It seems also there is no way to sort the table directly (I guess doing it through arrays should be feasable, if there is no other solution through the dataset...)
Answering to myself...
The only way I found is to re-run the dataset query every time a "sort" button is clicked, with the sort in the query, instead of running only a dataset.setSort() :
export function button2_click(event) { // sort on team $w('#dataset1').refresh(); $w('#dataset1').onReady(() => { let dpd = $w('#dropdown1').value; if (dpd === '') { // '#dropdown1' is empty if no season selected yet dpd = $w('#dropdown1').placeholder;} var lowerYear = dpd.substring(0,4); var upperYear = dpd.substring(5,9); var lowerDate = new Date(lowerYear.concat('-','9','-','1')); var upperDate = new Date(upperYear.concat('-','6','-','30')); wixData.query('match') .gt('dateHeure', lowerDate) .lt('dateHeure', upperDate) .ascending('equipe') .limit(300) .find() .then( (res) => { let tableRows = res.items; $w('#table1').rows = tableRows; }) }) }