How to use Kendo UI Grid with ToDataSourceResult(), IQueryable, ViewModel and AutoMapper?

前端 未结 6 1591
轻奢々
轻奢々 2021-02-02 01:00

What is the best approach to load/filter/order a Kendo grid with the following classes:

Domain:

public class Car
{
    public virtual in         


        
6条回答
  •  后悔当初
    2021-02-02 01:37

    I followed the suggestion of CodingWithSpike and it works. I created an extension method for the DataSourceRequest class:

    public static class DataSourceRequestExtensions
        {
            /// 
            /// Finds a Filter Member with the "memberName" name and renames it for "newMemberName".
            /// 
            /// The DataSourceRequest instance. 
            /// The Name of the Filter to be renamed.
            /// The New Name of the Filter.
            public static void RenameRequestFilterMember(this DataSourceRequest request, string memberName, string newMemberName)
            {
                foreach (var filter in request.Filters)
                {
                    var descriptor = filter as Kendo.Mvc.FilterDescriptor;
                    if (descriptor.Member.Equals(memberName))
                    {
                        descriptor.Member = newMemberName;
                    }
                } 
            }
        }
    

    Then in your controller, add the using to the extension class and before the call to ToDataSourceResult(), add this:

    request.RenameRequestFilterMember("IsActiveText", "IsActive");
    

提交回复
热议问题