DataGrid is not displaying results from an ODataV4Adaptor

Good day

I have a grid

    <ejs-grid id="Grid" toolbar="@(new List<string>() { "Add", "Update", "Cancel" })" allowPaging="true" allowSorting="true" allowFiltering="true" actionFailure="actionFailure" >
        <e-data-manager url="https://localhost:44321/odata/persons/" adaptor="ODataV4Adaptor" crossdomain="true" ></e-data-manager>
        <e-grid-pagesettings pageSize="7">
        </e-grid-pagesettings>
        <e-grid-columns>
            <e-grid-column field="ID" headerText="ID" isPrimaryKey="true" textAlign="Right" width="120"></e-grid-column>
            <e-grid-column field="FirstName" headerText="First Name" width="150"></e-grid-column>
            <e-grid-column field="LastName" headerText="Last Name" width="150"></e-grid-column>
            <e-grid-column field="DateOfBirth" headerText="Date of Birth" width="120"></e-grid-column>
        </e-grid-columns>
    </ejs-grid>

The odata call returns

{"message":"Request successful.","isError":false,"result":{"@odata.context":"https://localhost:44321/odata/$metadata#Persons","@odata.count":14,"value":[
{"ID":7,"FirstName":"John","LastName":"Smith","DateOfBirth":"1990-02-11T21:30:22-04:00"},
{"ID":10,"FirstName":"David","LastName":"Davids","DateOfBirth":"2020-02-11T21:30:22-04:00"},
{"ID":11,"FirstName":"Test1","LastName":"Test1","DateOfBirth":"2020-02-11T21:30:22-04:00"},
{"ID":12,"FirstName":"Test2","LastName":"Test2","DateOfBirth":"2020-02-11T21:30:22-04:00"},
{"ID":13,"FirstName":"Test3","LastName":"Test3","DateOfBirth":"2020-02-11T21:30:22-04:00"},
{"ID":14,"FirstName":"Test4","LastName":"Test4","DateOfBirth":"2020-02-11T21:30:22-04:00"},
{"ID":15,"FirstName":"Test5","LastName":"Test5","DateOfBirth":"2020-02-11T21:30:22-04:00"}]}}

but the grid is not being populated with the data


7 Replies

SK Sujith Kumar Rajkumar Syncfusion Team March 13, 2020 12:35 PM UTC

Hi Ronald, 
 
Greetings from Syncfusion support. 
 
We checked your reported problem but unfortunately were unable to reproduce it from our end as the data returned from ODataV4Adaptor was bound to the Grid properly. 
 
We suspect you might be facing this issue due to serialization problems. In ASP.NET Core, by default the JSON results are returned in camelCase format. So grid field names are also changed in camelCase. 
To avoid this problem, you need to add DefaultContractResolver in Startup.cs file of your application. 
 
If the ASP.NET CORE version is 2.X then add the below code in startup.cs file 
 
public void ConfigureServices(IServiceCollection services) { 
            services.AddMvc().AddJsonOptions(options => 
            { 
                options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); 
            }); 
} 
 
If the ASP.NET CORE version is 3.X then add the below code in startup.cs file 
 
public void ConfigureServices(IServiceCollection services) { 
            services.AddMvc().AddNewtonsoftJson(options => 
            { 
            options.SerializerSettings.ContractResolver = 
               new DefaultContractResolver()); 
        } 
} 
 
 
We have prepared a sample based on this for your reference which you can find below, 
 
 
Please get back to us if the problem is still not resolved or if you require further assistance. 
 
Regards, 
Sujith R 



RW Ronald Walcott March 13, 2020 04:59 PM UTC

Good day

It appears as if the grid is unable to handle API responses which use API exception handler and the EDM model. With the example you provided, the response from the API is not wrapped in
 
{"message":"Request successful.","isError":false,"

as mine is.

My API project contains

app.UseApiResponseAndExceptionWrapper()

in the startup. 

If I remove this the grid works.

The project that I am using it on is only a test project examining OData and ASP .NET Core 3.1 I can provide a copy of it if you need to do further investigations.

Thank you


SK Sujith Kumar Rajkumar Syncfusion Team March 16, 2020 09:12 AM UTC

Hi Ronald, 

Thanks for the update. 

Could you please share us the project to validate further on your reported scenario. 
  
Regards, 
Sujith R 



RW Ronald Walcott March 16, 2020 04:46 PM UTC

Good day

The solution is available at https://github.com/ronaldwalcott/ApiBoilerPlateMyTest

It is based on an API template https://github.com/proudmonkey/ApiBoilerPlate which uses Dapper but I am changing it to use Entity Framework Core and one of my personal test templates.

The related TestDBContext database in the API project of the solution needs to be created and the Person entity populated. Both projects should start and create two browser windows, Ignore the browser window which doesn't show the home view of the APiBoilerPlateWeb project (that browser window is just a test window configured in the API project).

Commenting and uncommenting app.UseApiResponseAndExceptionWrapper() in startup.cs of the API project should show that data displays in the grid based on this, only when OData EDM is used, which is necessary to retrieve the count of records. It should be noted that the version of OData used is Microsoft.AspNetCore.OData 7.4.0-beta which is necessary to use the new ASP .NET Core 3.x (I think it's from version 3) endpoint configuration. 


SK Sujith Kumar Rajkumar Syncfusion Team March 17, 2020 01:33 PM UTC

Hi Ronald, 

Thanks for the update and the sample. 

The response returned from OData service must be in the below format from which the count and data is assigned to the Grid. 

 

Since the response sent from your API service contains the value and response inside a separate object in result it is not getting bound to the Grid properly. So we suggest you to use Custom Adaptor(Own adaptor extended from the built-in adaptors) to bind data to the Grid and override its ProcessResponse method(built-in response processing method) and return the response value and count as result and count properties respectively from this method. Using custom adaptor and overriding its ProcessResponse method to modify the resultant data is already documented in our online help documentation site which you can access from the following link, 


Let us know if you have any concerns. 

Regards, 
Sujith R 



RW Ronald Walcott March 18, 2020 12:53 AM UTC

Thank you


SK Sujith Kumar Rajkumar Syncfusion Team March 18, 2020 05:59 AM UTC

Hi Ronald, 

No problem. We are happy to assist you. 

Please get back to us if you require further assistance. 

Regards, 
Sujith R 


Loader.
Up arrow icon