Sorting Dropdown List on Add/Edit

I have a dropdown list for inventory Items. When the user edits/add a tool I want to Display the dropdown in Ascending order by the inventory Id instead of the Description.
Right now the dropdown sorts by the description, I want to sort by the inventory id.
Code:

 var inventoryList = new Syncfusion.EJ2.DropDowns.DropDownList() { DataSource = @Model.Inventory, Query = "new ej.data.Query()", AllowFiltering = true, SortOrder = "", Fields = new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings() { Value = "InventoryID", Text = "Description" } };
  

    <ejs-grid id="Grid" [email protected] dataBound="dataBound" height="510px" allowPaging="true" allowSorting="true" allowFiltering="true" allowGrouping="true" allowReordering="true" allowResizing="false" allowMultiSorting="true" allowPdfExport="true" allowExcelExport="true" showColumnChooser="true" toolbarClick="toolbarClick" printComplete='printComplete'  actionComplete="actionComplete" actionBegin="actionBegin" toolbar="@(new List<string>() {"Add","Edit","Print", "PdfExport", "ExcelExport", "Search", "ColumnChooser"})">
        <e-grid-groupsettings></e-grid-groupsettings>
        <e-grid-filterSettings columns="filterColumns" type="Excel"></e-grid-filterSettings>
        <e-grid-pagesettings pageCount="6" pageSize="16" pageSizes="@(new string[] {"5", "10", "16", "20", "All"})"></e-grid-pagesettings>
        <e-grid-sortsettings columns="cols"></e-grid-sortsettings>
        <e-grid-editSettings allowAdding="true" allowEditing="true" mode="Dialog"></e-grid-editSettings>
        <e-data-manager json="@Model.Tools.ToArray()" adaptor="RemoteSaveAdaptor" insertUrl="/Home/AddTool" updateUrl="/Home/UpdateTool"></e-data-manager>
        <e-grid-columns>
          ...
            <e-grid-column field="InventoryID" headerText="Description" minWidth="120" editType="dropdownedit" edit="new {@params = inventoryList }" validationRules="@(new {required = true})" visible="false" width="120"></e-grid-column>
           
        </e-grid-columns>
    </ejs-grid>

1 Reply 1 reply marked as answer

SK Sujith Kumar Rajkumar Syncfusion Team April 21, 2021 12:46 PM UTC

Hi Danyelle, 
 
Greetings from Syncfusion support. 
 
We checked the query and would like to let you know that by default, the EJ2 DropDown List will be sorted with help of mapped “text” field. However, you can achieve the requirement of sorting based on another property(present in the data source) by passing the required field in the sortBy() method of the query property as demonstrated in the below code snippet, 
 
@{ 
    var inventoryList = new Syncfusion.EJ2.DropDowns.DropDownList() { DataSource = ViewBag.Data, SortOrder = "", Query = "new ej.data.Query().sortBy('InventoryID')", AllowFiltering = true, Fields = new Syncfusion.EJ2.DropDowns.DropDownListFieldSettings() { Value = "InventoryID", Text = "Description" } }; 
} 
   
 
Please get back to us if you require any further assistance. 
 
Regards, 
Sujith R 


Marked as answer
Loader.
Up arrow icon