Can the table element on user input fields by any means be sortable by users when rendered on the website for them at this time?
Hi Omid,
The answer is yes, but you’ll need to add some code to your page to make it happen. The table itself doesn’t support sorting, but the dataset does. Once you apply sorting to your dataset, the content of the table will also be sorted.
You should see the API here to learn about the setSort function: wix-dataset - Velo API Reference - Wix.com. But here is the basic code you need to make it work.
In this code I’m assuming you added 2 buttons to your site, one with the ID AtoZ and the other ZtoA. I’ve added a click event to each button and then added the following code to each event handler. Here I’m also assuming you are sorting on the “Title” field. Note that you can sort on any text, number, or date field.
export function AtoZ(event) {
$w(“#dataset1”).setSort(wixData.sort()
.ascending(“Title”));
}
export function ZtoA(event) {
$w(“#dataset1”).setSort(wixData.sort()
.descending(“Title”));
}
Don’t forget to add this line to the top of your code:
import {wixData} from ‘wix-data’;
import wixData from ‘wix-data’ ;
// this is radio button
export function iptsort_change ( event )
{
if ( $w ( “#iptsort” ). value === ‘Alphabetical’ )
{
$w ( “#dataset1” ). setSort ( wixData . sort (). ascending ( “name” ));
}
else if ( $w ( “#iptsort” ). value === ‘Birth year’ )
{
$w ( “#dataset1” ). setSort ( wixData . sort (). descending ( “dateOfBirth” ));
}
else if ( $w ( “#iptsort” ). value === ‘Newest’ )
{
$w ( “#dataset1” ). setSort ( wixData . sort (). descending ( “_createdDate” ));
}
}