top of page

Dataset Sort

Sort dataset using dropdown or radio input elements.

Untitled (800 x 600 px) (1).png

Lightbox Show Hide

Popup Custom

Ecom Add To Cart

Dataset Search

Dynamic Pages Previous Next

Dynamic Pages Show Hide Element

Forms Save Progress

Dataset Sort

Show Hide Elements

Dataset Pagination

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