Sort lookup dropdown values in List or Library control

Hello,
How do i sort the drop down values for a lookup field in a List or Library control? I want to sort alphabetically. Thanks!

image

Dear @ParAvion,
Please, try the following code, just replace Lookup's Internal Name and Title with the Internal Name of the field you lookup:

fd.spRendered(function() {
    fd.control('SPDataTable1').$on('edit', function(editData) {
        editData.field('Lookup').orderBy = { field: 'Title', desc: true };
    });
});

Hi,

I was never able to get this to work....the lookup list is still not in alphabetical order. Can you please assist?

Thanks.

Hello @ParAvion,

To order records in alphabetical order, you need to set the desc parameter to false:

    fd.control('SPDataTable1').$on('edit', function(editData) {
        editData.field('Lookup').orderBy = { field: 'Title', desc: false };
    });

Also, make sure that you've replaced Title with the internal name of the column set as the source of the lookup field.

It only works in Dialog....is there a way to get it to work with Inline too? Thanks!

Dear @ParAvion,
What do you mean? This code is specific to the Inline editing mode, and wouldn't work with Dialog mode (in Dialog mode, you need to write JS code on the form that opens in dialog).

Here's what a sorted lookup looks like with this code:

Hi,

I used you code on an inline, and the lookup dropdown doesn't sort alphabetically. If I switch it to a dialog, the list DOES sort alphabetically:

Code:
image

Inline:
image

Dialog:

Dear @ParAvion,
The code doesn't affect the dialog mode in any way - seems like it's just a standard SharePoint form behavior.

Are you sure that you're using the correct Internal Name for the lookup column? You need to replace 'Lookup' in editData.field('Lookup') with the actual Internal Name of the lookup column that you want to filter.

To get its Internal Name, go to the child list, open list settings and click on the Lookup column, the Internal Name will be available in URL:

The internal lookup name of the field is "Item", but the list still won't order itself. I really don't know what the issue is.

image

image

Dear @ParAvion,
Okay, and what's the field that you want to order by? Do you want to order the Item field by Item? Or maybe by Title instead?

fd.control('SPDataTable1').$on('edit', function(editData) {
  editData.field('Item').orderBy = { field: 'Title', desc: false };
});

I simply want the items in my lookup list to appear alphabetically. I've tried every way you've suggested but nothing works.

Dear @ParAvion,
There are a lot of factors to take into account - which we cannot account for, it depends on your setup. The code is simple, you just need to use correct Name for the List or Library control, correct Internal Name for the lookup column, and correct Internal Name for the field displayed in the lookup.

What's the field that you display in Item lookup? I mean this field, in my screenshot it's SingleLine:
image

You need to check the Internal Name for this field, and use it in the code:

fd.control('SPDataTable1').$on('edit', function(editData) {
  editData.field('Item').orderBy = { field: 'SingleLine_InternalName', desc: false };
});

Thanks for helping out:

The internal name of 'ItemName' is 'Title'.

Dear @ParAvion,
If it's Title, then the code should be this:

fd.control('SPDataTable1').$on('edit', function(editData) {
  editData.field('Item').orderBy = { field: 'Title', desc: false };
});

Just make sure that the List or Library control name is SPDataTable1:

Thank you for your efforts but this still isn't working for me.

Dear @ParAvion,
If this is the case, please, check the browser's console for errors when the form opens, as well as check Sources tab in the dev tools for version number of web part and widget:
image

Send us screenshots of both, please.

@Nikita_Kurguzov thanks I've got it working now!