top of page
This website was created by Liquis

Dataset Sort

Sort dataset using dropdown or radio input elements.

Dataset Sort

Dataset Pagination

Dataset Search

Dataset Sort

Dynamic Pages Previous Next

Dynamic Pages Show Hide Element

Ecom Add To Cart

Forms Save Progress

Lightbox Show Hide

Popup Custom

Show Hide Elements

All Snippets

Features

  • Sorting using radio or dropdown elements

  • Sort in ascending or descending order

New to our site? Please see our quick tutorial on how to work with our snippets

View tutorials

Setting
Description

$w.onReady(() => {
DatasetSort({
elementId: '#dropdown1',
datasetId: '#dataset1',
options: [
{ label: 'First Name (A - Z)', value: 'firstName' },
{ label: 'First Name (Z - A)', value: 'firstName__desc' },
{ label: 'Last Name', value: 'lastName' },
{ label: 'Recently Added', value: '_createdDate' }
]
})
})

async function DatasetSort({datasetId:n,elementId:e,onChange:t=null,options:a}){
if(!e||!n)return;const o=$w(e);if(!o?.id)return;const s=$w(n);if(!s?.id)return
;await s.onReadyAsync();const i=require("wix-data");o.options=[...a,{
label:"None",value:"_none"}];var c=async()=>{const[n,e]=o.value.split("__")
;await l(s,n,e),"function"==typeof t&&t()}
;o.onChange(c),o.value&&o.value.length&&c();const l=async(n,e,t)=>{
let a=i.sort()
;if(e&&"_none"!==e)if("desc"===t)a=a.descending(e);else a=a.ascending(e)
;await n.setSort(a)}}

Title

Title

bottom of page