MVC Grid sort on editortemplate dropdownlist column

0 Answers 1 View
DropDownList Grid
Cynthia
Top achievements
Rank 1
Iron
Cynthia asked on 22 Jan 2026, 10:05 PM
Hi, I'm asking about an answer posted in the Sorting Grid on Editor Template column post back in 2017.  The answer was from Georgi and here is the excerpt: 

public ActionResult Read([DataSourceRequest] DataSourceRequest request) { // Check if any sorts have been applied.if (request.Sorts != null) { // Loop through each sort.foreach (var sort in request.Sorts) { // Check if the Category column is being sortedif (sort.Member == "Category") { // Sort by the CategoryName instead of the Object. sort.Member = "Category.CategoryName"; } } } }

 

My grid column coincidentally also has to do with categories. I tried adding the above code to my read method and it doesn't work. When I click on the header to sort the column it doesn't automatically initiate a read call so I'm not sure how this could work. I guess I'm missing something.

My grid definition:

@(
Html.Kendo().Grid<LookupItem>()
    .Name("LookupList")
    .Columns(columns =>
    {
        columns.Bound(m => m.Id).Hidden(true);
        columns.Bound(m => m.CategoryListItem).ClientTemplate("#: CategoryListItem.CategoryName #").EditorTemplateName("LookupCategoryDropDown").Width("25%"); ;
        columns.Bound(m => m.Name).Width("25%");
        columns.Bound(m => m.Value).Width("15%");
        columns.Bound(m => m.AlternativeValue).Width("15%");
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
    })
    .ToolBar(toolbar => { toolbar.Create().Text("Add New Lookup Item"); })
    .Editable(editable => editable.Mode(GridEditMode.InLine).DisplayDeleteConfirmation("Are you sure you want to delete this item?"))
    .Sortable()
    .Scrollable()
    .Filterable(filterable => filterable.Extra(false))
    .Pageable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(50)
        .ServerOperation(false)
        .Model(model =>
        {
            model.Id(m => m.Id);
            model.Field(m => m.Category);
            model.Field(m => m.Name);
            model.Field(m => m.Value);
            model.Field(m => m.AlternativeValue);

        })
        .Read(read => read.Action("Lookup_Read", "Lookup"))
        .Create(create => create.Action("Lookup_Create", "Lookup"))
        .Update(update => update.Action("Lookup_Update", "Lookup"))
        .Destroy(read => read.Action("Lookup_Delete", "Lookup"))
    )

My Controller Read Method:

 public async Task<IActionResult> Lookup_Read([DataSourceRequest] DataSourceRequest request)
 {
     if (request.Sorts != null)
     {
         // Loop through each sort.
         foreach (var sort in request.Sorts)
         {
             // Check if the Category column is being sorted
             if (sort.Member == "CategoryListItem")
             {
                 // Sort by the CategoryName instead of the Object.
                 sort.Member = "CategoryListItem.CategoryName";
             }
         }
     }
     var model = await _service.GetAllLookupTypesAsync();
     var result = model.ToDataSourceResult(request);
     return Json(result);

 }               

No answers yet. Maybe you can help?

Tags
DropDownList Grid
Asked by
Cynthia
Top achievements
Rank 1
Iron
Share this question
or