Sorting

18 Nov 20183 minutes to read

The ComboBox has built-in support to sort data items when SortOrder is specified. The available sort orders are ascending, descending and none.

To sort the data in ascending order, set the SortOrder as ascending.

The following sample illustrates how to sort the data.

  • HTML
  • <div class="frame">
            <div class="control"> 
            <ej-combo-box id="select" datasource="(IEnumerable<Countries>)ViewBag.datasource" placeholder="Select" sort-order="Ascending">
                <e-combo-box-fields text="text"/>
            </ej-combo-box>
            </div>
        </div>
  • C#
  • public string text { get; set; }
            public string category { get; set; }
            public static List<Countries> GetCountries()
            {
                List<Countries> country = new List<Countries>();
                country.Add(new Countries { text = "Austria", category = "A" });
                country.Add(new Countries { text = "Australia", category = "A" });
                country.Add(new Countries { text = "Antarctica", category = "A" });
                country.Add(new Countries { text = "Bangladesh", category = "B" });
                country.Add(new Countries { text = "Brazil", category = "B" });
                country.Add(new Countries { text = "Canada", category = "C" });
                country.Add(new Countries { text = "Cuba", category = "C" });
                country.Add(new Countries { text = "Denmark", category = "D" });
                country.Add(new Countries { text = "Dominica", category = "D" });
                return country;
            }
        }
    }

    Output for Sorting is as follows.