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.
Unfortunately, activation email could not send to your email. Please try again.

OData sorting broken in version 14.2.0.28

Thread ID:

Created:

Updated:

Platform:

Replies:

125364 Aug 10,2016 05:42 PM Aug 15,2016 02:41 AM ASP.NET MVC 6
loading
Tags: Grid
jrlewis
Asked On August 10, 2016 05:42 PM

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 ".".


Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On August 11, 2016 09:29 AM

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. 


jrlewis
Replied On August 11, 2016 12:38 PM

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();
    })
)




jrlewis
Replied On August 11, 2016 07:26 PM

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

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On August 12, 2016 12:03 PM

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. 


jrlewis
Replied On August 12, 2016 02:59 PM

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".

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On August 15, 2016 02:41 AM

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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;