Sort Data from Common Dropdown

I have a common dropdown that I would like to sort. How would I do that?

Hello @cwalter2,

For a Choice Field, the order in which the items in the drop-down are presented is the order in which they are listed in the field settings.

image

You can either change the order in the field settings or use the Lookup Field instead. For a lookup field, you can sort and filter values in the drop-down dynamically. Please see the example here.

What I was actually going for was a Plumsail Common Dropdown which I was populating with Sharepoint Fields. I was using this to add items via pnp to another list.

Hello @cwalter2,

Ok, now it's clear.

You can sort the array that you get from the other list before populating DropDwon field with values using the sort() method. For instance:

    var siteURL = 'SiteURL';
    let web = new Web(siteURL);

    web.lists.getByTitle('ListName').items.select('Title').get().then(function(items) {
        //get values from the list
        options = items.map(function(i) { return i.Title })
        fd.field('DropDown1').widget.setDataSource({
            //sort the array and populate DropDwon             
            data: options.sort()
        });

    });

Hi @mnikitina ,

I am wondering how I can iterate through the dropdown items in Javascript?

Thanks,

Hello @jyou,

Please provide more details about your case.

Do you need to iterate through field values or options? What type of a filed is it: common drop down, lookup?

Hi @mnikitina ,

I linked a Sharepoint list named "Details" to a Dropdown type column in a datatable using the following code below:

image
image

How do I iterate through the options in the dropdown that come from the Sharepoint list?

Thanks

@jyou,

You can try out this code:

    var siteURL = 'SiteURL';
    let web = new Web(siteURL);

    web.lists.getByTitle('ListName').items.select('Title').get().then(function(items) {
        //iterate through list items
        items.forEach(function(item){
        	console.log(item.Title)
        })

    });