amritbhgt
02-13-2024Cloud Apps
Add a drop-down for sorting
Hi,
I want to add a drop down to sort the blox based on what we have selected in that.
Eg. i have chosen # Submission that blox should be sorted based on that and user can select any field from the drop down.
Hi amritbhgt ,
The code below assumes that the dropdown has an ID of selectVal, and has a value associated with the title that is the same as the index of the item you want to sort by on the BloX. e.g. if you want to sort by '# Submission', and the '# Submission' is the third item in total on the BloX, you would set the value in the dropdown to 2.
widget.on('processresult', (w, args) => { // this is the 'value' of the selected dropdown title. const index = Number($('#selectVal').val()) args.result.sort((a, b) => { if (a[index].Value < b[index].Value) { return 1 } else { return -1 } }) })
When you click the sort button, you should do a widget.refresh() on the target BloX widget.
Let me know how you go?