Forum Discussion

amritbhgt's avatar
amritbhgt
Cloud Apps
02-13-2024
Solved

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?

3 Replies

Replies have been turned off for this discussion
  • 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?
  • Hello amritbhgt ,

    Did the solution offered by rapidbisupport work for you? If so, please click the 'Accept as Solution' button so that other users with the same questions can find the answer faster. If not, please let us know so that we can continue to help.

    Thank you.

  • Hello @amritbhgt,

    Did the solution offered by @rapidbisupport work for you?

    If so, please click the 'Accept as Solution' button so that other users with the same questions can find the answer faster. If not, please let us know so that we can continue to help.

    Thank you.