Sorting not working on server with "PerformSorting" method for nested item.

I have an object having nested items. I have used UrlAdapter as a data source cause I have to deal with more than 600,000 data. For example, I have a book class having multiple authors. 

Class Book{

    List<Author> Authors {get; set;}

}

Class Author{

    string AuthorName {get; set;}

}

In grid data populated successfully. I used the following way to bind remote data to the grid.

    <e-grid-column field="Author.AuthorName" headerText="Employee Name" clipMode="EllipsisWithTooltip">      </e-grid-column>

Now I want to sort this column. I have user the following definition for initial sort.

List<object> sortingCols = new List<object>() {

       new { field = " Author.AuthorName", direction = "ascending" }

    };


On the server-side I get this information accurately but "DataOperations.PerformSort()" methods through an error. It can't sort the nested item. Is there any alternative to that?



1 Reply

RR Rajapandi Ravi Syncfusion Team December 14, 2021 12:51 PM UTC

Hi Mehadi, 

Greetings from Syncfusion support 

From your update, we could see that you are using complex data binding and facing problem while perform sorting on the server-side. Based on your query we have prepared a sample and try to reproduce your reported problem, but it was working fine at our end. Please refer the below code example and sample for more information. 

Index.cshtml 

<ejs-grid id="Grid" allowPaging="true" allowSorting="true" toolbar="@(new List<string>() {"Search" })"> 
    <e-data-manager url="/Home/UrlDatasource" adaptor="UrlAdaptor"></e-data-manager> 
    <e-grid-columns> 
        <e-grid-column field="EmployeeID" headerText="Employee ID" width="100"></e-grid-column> 
        <e-grid-column field="Customer.CustomerId" headerText="ID" width="120"></e-grid-column> //complex data binding columns 
        <e-grid-column field="Customer.Name" headerText="Name" width="100"></e-grid-column> 
    </e-grid-columns> 
</ejs-grid> 

HomeController.cs 

public IActionResult UrlDatasource([FromBody]DataManagerRequest dm) 
        { 
            IEnumerable<OrdersData> DataSource = OrdersData.GetAllRecords().AsEnumerable();  
            DataOperations operation = new DataOperations(); 
            List<string> str = new List<string>(); 
            if (dm.Aggregates != null) 
            { 
                for (var i = 0; i < dm.Aggregates.Count; i++) 
                    str.Add(dm.Aggregates[i].Field); 
            } 
            IEnumerable aggregate = operation.PerformSelect(DataSource, str); 
 
            if (dm.Search != null && dm.Search.Count > 0) 
            { 
                DataSource = operation.PerformSearching(DataSource, dm.Search);  //Search 
            } 
            if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting 
            { 
                DataSource = operation.PerformSorting(DataSource, dm.Sorted); 
            } 
            if (dm.Where != null && dm.Where.Count > 0) //Filtering 
            { 
                DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); 
            } 
            int count = DataSource.Cast<OrdersData>().Count(); 
            if (dm.Skip != 0) 
            { 
                DataSource = operation.PerformSkip(DataSource, dm.Skip);   //Paging 
            } 
            if (dm.Take != 0) 
            { 
                DataSource = operation.PerformTake(DataSource, dm.Take); 
            } 
            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource); 
        } 

public class OrdersData 
        { 
            public static List<OrdersData> 
    order1 = new List<OrdersData> 
        (); 
            public OrdersData() 
            { 
 
            } 
            public OrdersData(int UnitID, int N2, int N1, int EmployeeId, Customer Customer, string ShipName, string ShipAddress) 
            { 
                this.UnitID = UnitID; 
                this.N1 = N1; 
                this.N2 = N2; 
                this.EmployeeID = EmployeeId; 
                this.Customer = Customer; 
                this.ShipName = ShipName; 
                this.ShipAddress = ShipAddress; 
            } 
            public static List<OrdersData> 
                GetAllRecords() 
            { 
                if (order1.Count() == 0) 
                { 
                    int code = 10; 
                    for (int i = 1; i < 3; i++) 
                    {                                                  //set the value here for another model class fields 
                          order1.Add(new OrdersData(code+1,28, 16, 3,new Customer { CustomerId = 7, Name = "Vinet" }, " bistro", "Kirchgasse 6")); 
                        order1.Add(new OrdersData(code + 1, 10, 15, 2, new Customer { CustomerId = 5, Name = "John" }, " Cozinha""Avda. Azteca 123")); 
                        order1.Add(new OrdersData(code + 2, 15 ,29, 3, new Customer { CustomerId = 9, Name = "Scott" }, "Frankenversand", "Carrera 52 con Ave. Bolívar #65-98 Llano Largo" )); 
                        order1.Add(new OrdersData(code + 3, 18, 30, 4, new Customer { CustomerId = 1, Name = "Robert" }, " Handel","Magazinweg 7")); 
                        order1.Add(new OrdersData(code + 4, 22, 25, 1, new Customer { CustomerId = 4, Name = "James" }, " Carnes","1029 - 12th Ave. S.")); 
                        code += 5; 
                    } 
                } 
                return order1; 
            } 
            public int? UnitID { get; set; } 
            public int? EmployeeID { get; set; } 
 
            public int? N1 { get; set; } 
            public int? N2 { get; set; } 
            public  Customer Customer { get; set; } 
            public string ShipName { get; set; } 
            public string ShipAddress { get; set; } 
 
        } 
        public class Customer //another model class 
        { 
            public static List<Customer> order1 = new List<Customer>(); 
            public Customer() 
            { 
 
            } 
 
            public long CustomerId { get; set; } 
            public string Name { get; set; } 
        } 
 


Regards, 
Rajapandi R 


Loader.
Up arrow icon