We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

OData sorting broken in version 14.2.0.28

With version 14.1.0.46 the following

@(Html.EJ().Grid<Inventory>(String.Format("{0}Grid", entity))
            .Datasource(ds => ds.URL("/odata/" + controller).Adaptor(AdaptorType.ODataV4Adaptor))
            .AllowFiltering()
            .AllowSorting()
            .SortSettings(b => b.SortedColumns(col => col.Field("Warehouse.Name").Direction(SortOrder.Ascending).Add()))
        .AllowPaging()
        .EnablePersistence(true)
        .AllowSelection(false)
        .EnableRowHover(false)
        .Query("new ej.Query().select(['Id', 'Location', 'Quantity']).expand('Warehouse($select=Id,Name),Product($select=Id,Name,SKU)')")
...

would produce a valid odata request.  Note that the orderby for the complex property is handled correctly.

http://localhost:54849/odata/Inventories/?$expand=Warehouse($select=Id,Name),Product($select=Id,Name,SKU),Warehouse,Product&$select=Id,Location,Quantity&$count=true&$orderby=Warehouse/Name&$skip=0&$top=12

After upgrading to 14.2.0.28 orderby is now just $orderby=Name.  I did some testing and it appears that the field property on the sorted column is being parsed and set to everything after the last ".".


6 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 11, 2016 01:29 PM UTC

Hi Bob, 

We are unable to reproduce the issue at our end.  

We suspect that your query is incorrect. In our previous versions, Expand query is not working correctly for the ODataV4Adaptor. So we have included the fix in the current version 14.2.0.28. So we suggest to follow the below code example. For complex binding use only the expand query of ej.Query(). 

@(Html.EJ().Grid<object>("FlatGrid") 
        .Datasource(ds =>  
            ds.URL("http://services.odata.org/V4/Northwind/Northwind.svc/Customers") 
            .Adaptor(AdaptorType.ODataV4Adaptor)) 
        .AllowFiltering() 
        .AllowSorting() 
        .SortSettings(b =>  
            b.SortedColumns(col =>  
                col.Field("Orders.0.Customer.CustomerID") 
                .Direction(SortOrder.Ascending).Add())) 
              . . .  
        .Query("new ej.Query().select(['CompanyName']).expand(['Orders'])") 
         . . .  
) 

Check the following Request URL as result of the above code example: 


We have also prepared a sample that can be downloaded from the following location. 


If you are still facing any issue please, provide the following information to replicate the issue. 

1)      Sample code example and structure of the data bound to the Grid 
2)      Share the generated Request URL 
3)      If possible, modify the attached sample and replicate the issue. 

Regards, 
Seeni Sakthi Kumar S. 



JR jrlewis August 11, 2016 04:38 PM UTC

This is a bad example.  The reason it works is because you are sorting on the CustomerID which belongs to the customer entity. The url you show clearly shows how the sorted column is being parsed.  If you try and select the OrderID column for sorting you will see that gives an error that OrderID is not found on the Customer entity. The other reason this isn't a good example is the orders is a many relationship.  A better example is shown below.  It simply shows the Orders with expanding the CompanyName for the Customer property.  It shows how you can get a valid sort when the grid is first loaded, but it fails when you select the CompanyName header since it is not parsing the property correctly.

@{
    ViewBag.Title = "Home Page";
}

@(Html.EJ().Grid<object>("FlatGrid")
        .Datasource(ds =>
            ds.URL("http://services.odata.org/V4/Northwind/Northwind.svc/Orders")
            .Adaptor(AdaptorType.ODataV4Adaptor))
        .AllowFiltering()
        .AllowSorting()
        .SortSettings(b =>

                // This breaks because of improper parsing
                //b.SortedColumns(col =>
                //    col.Field("Customer.CompanyName")
                //    .Direction(SortOrder.Ascending).Add())

                // This works for intial sort, but as soon as you select the column for sorting it breaks because of improper parsing 
                b.SortedColumns(col =>
                    col.Field("Customer/CompanyName")
                    .Direction(SortOrder.Ascending).Add())
                )
        .AllowPaging()
        //.EnablePersistence(true)
        .AllowSelection(false)
        .EnableRowHover(false)
        .Query("new ej.Query().select(['OrderID']).expand(['Customer($select=CompanyName)'])")
    .Columns(col =>
    {
        col.Field("OrderID").HeaderText("Order ID").Add();
        col.Field("Customer.CompanyName").HeaderText("Company Name").Add();
    })
)





JR jrlewis August 11, 2016 11:26 PM UTC

For the initial load of the grid the request url is 

http://services.odata.org/V4/Northwind/Northwind.svc/Orders/?$expand=Customer($select=CompanyName),Customer&$select=OrderID&$count=true&$orderby=Customer/CompanyName&$skip=0&$top=12

When the company name column is selected the generated url is the following

http://services.odata.org/V4/Northwind/Northwind.svc/Orders/?$expand=Customer($select=CompanyName),Customer&$select=OrderID&$count=true&$orderby=CompanyName&$skip=0&$top=12


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 12, 2016 04:03 PM UTC

Hi Bob, 

We are able to reproduce the problem at our end.  

To overcome this problem, please extend the onEachSort method of ODataV4Adaptor. 

@(Html.EJ().Grid<object>("FlatGrid") 
        .Datasource(ds => 
            ds.URL("http://services.odata.org/V4/Northwind/Northwind.svc/Orders") 
            .Adaptor(AdaptorType.ODataV4Adaptor)) 
        .EnableRowHover(false) 
            .Query("new ej.Query().select(['OrderID']).expand(['Customer'])") 
             
) 
 
<script> 
    var onEachSort = ej.ODataV4Adaptor.prototype.onEachSort; 
 
    ej.ODataV4Adaptor.prototype.onEachSort = function (e) { 
        var res = []; 
        if (!(e.name instanceof Array) && e.name.split(".").length > 1) { 
            res.push(this._p(e.name) + (e.direction === "descending" ? " desc" : "")); 
            return res.join(","); 
        } 
        return onEachSort.apply(this, [e]); 
    }; 
 
</script> 

We have also prepared a sample that can downloaded from the following location. 


Regards, 
Seeni Sakthi Kumar S. 



JR jrlewis August 12, 2016 06:59 PM UTC

This solution works.  You say you are able to reproduce it, but you don't say whether this is a bug that will be fixed or is considered a "feature".


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 15, 2016 06:41 AM UTC

Hi Bob, 

Yes, we confirm the reported issue as a bug and the fix for this issue will be available in our Volume 2 Service Pack 2, 2016 Release which has been scheduled to be rolled out by end of August, 2016. Until then, we recommend to use the  workaround updated in our previous post.  

Regards, 
Seeni Sakthi Kumar S.

Loader.
Live Chat Icon For mobile
Up arrow icon