How do I sort the options of select (Dropdown)

I have a select field as one of the columns in my datatable and I was wondering if the options can be sorted based on id

For e.g. the following options are constructed on the server side:

var typeOptions = [
    {
        "id": "1", "value": "Type_1"
    },
    {
        "id": "2", "value": "Type_2"
    },
    {
        "id": "3", "value": "Type_3"
    },
    {
        "id": "4", "value": "Type_4"
    },
    {
        "id": "5", "value": "Type_5"
    },
    {
        "id": "6", "value": "Type_6"
    },
    {
        "id": "7", "value": "Type_7"
    },
    {
        "id": "8", "value": "Type_8"
    },
    {
        "id": "9", "value": "Type_9"
    }
];

and the column is declared as following:

{
        id: "Type",
        header: "<span title='Type'>Type</span>",
        editor: "select", options: typeOptions, width: 100
}

Now I would like to sort these values in the dropdown based on id’s

Is that possible.

Note: These options are dynamically constructed on the server side, I am just posting some dummy values for the sake of understanding.

I would appreciate any help on this. Thanks.

Hello,

JSON passed to options will be stored in a DataCollection linked to the column. The best option is to initialize it separately and declare the sorting method as follows: https://snippet.webix.com/a2knqbgb

I was currently doing that as a work-around but not as clean and elegant as your solution. Appreciate the help. Thanks.

@Listopad it seem that the sort doesn’t work when the collection is used as filter options ??

https://snippet.webix.com/tcrnb64y

any workaround to this ??

I know I can use $sort in inputConfig, but the issue is that the sort is being called over and over, and I’m using too complicated server datatable with lot of filters and big list of options

https://snippet.webix.com/f5uxj6nd

Thanks in advance

Hi @Listopad it seem that the sort doesn’t work when the collection is used as filter options ??

https://snippet.webix.com/tcrnb64y

any workaround to this ??

I know I can use $sort in inputConfig, but the issue is that the sort is being called over and over, and I’m using too complicated server datatable with lot of filters and big list of options

https://snippet.webix.com/f5uxj6nd

Thanks in advance