OdataV4Adaptor

Hi support, i'm using the OData Stack in a asp.net core application. When i use the grid with the ODatav4Adaptor the result is: TypeError: this.model.currentViewData is undefined but if i use the WebApiAdaptor without changing the controller i've the correct result.

My controller is:
    [Route("[controller]/[action]")]
    [ApiController]
    public class PatientsController : ODataController
//    public class PatientsController : ControllerBase
    {
        private readonly DataContext _dataContext;
        private readonly IMapper _mapper;

        public PatientsController(DataContext dataContext, IMapper mapper)
        {
            _mapper = mapper;
            _dataContext = dataContext;

        }


        public PageResult<WebApplication1.ViewModels.Patients> GetPage(ODataQueryOptions<WebApplication1.Models.PatientsView> options)
        {

            IQueryable<WebApplication1.Models.PatientsView> result = _dataContext.PatientsView;



            if (options?.Filter != null)
                result = options.Filter.ApplyTo(result, new ODataQuerySettings()) as IQueryable<WebApplication1.Models.PatientsView>;

            int count = result.Count();

            if (options?.OrderBy != null)
                result = options.OrderBy.ApplyTo(result, new ODataQuerySettings()) as IQueryable<WebApplication1.Models.PatientsView>;

            if (options?.Skip != null)
                result = options.Skip.ApplyTo(result, new ODataQuerySettings()) as IQueryable<WebApplication1.Models.PatientsView>;

            if (options?.Top != null)
                result = options.Top.ApplyTo(result, new ODataQuerySettings()) as IQueryable<WebApplication1.Models.PatientsView>;

            IEnumerable<WebApplication1.ViewModels.Patients> patientsDto = _mapper.Map<IEnumerable<WebApplication1.ViewModels.Patients>>(result.ToList());
            return new PageResult<WebApplication1.ViewModels.Patients>(patientsDto as IEnumerable<WebApplication1.ViewModels.Patients>, null, count);
        }

and my grid is defined as following:
<div class="form-group row">
    <ej-grid id="GridPatients" row-data-bound="provascript">

        <e-datamanager id="patientDataManager" url="/Patients/GetPage" adaptor="ODataV4Adaptor"></e-datamanager>

        <e-page-settings enable-templates="false" show-defaults="true" page-size="5"></e-page-settings>

        <e-sort-settings>
            <e-sorted-columns>
                <e-sorted-column field="LastName" direction="Ascending"></e-sorted-column>
                <e-sorted-column field="FirstName" direction="Ascending"></e-sorted-column>
            </e-sorted-columns>
        </e-sort-settings>

        <e-columns>
            <e-column field="Id" visible="false"></e-column>
            <e-column field="TitleAbbr" header-text="Title" header-text-align="TextAlign.Center" text-align="Center" width="60"></e-column>
            <e-column field="FirstName" header-text="First Name" header-text-align="TextAlign.Center" text-align="Center" width="100"></e-column>
            <e-column field="LastName" header-text="Last Name" header-text-align="TextAlign.Center" text-align="Center" width="100"></e-column>
            <e-column field="BirthDate" header-text="Birth Date" header-text-align="TextAlign.Center" text-align="Center" width="60"
                      edit-type="Datepicker" format="{0:dd/MM/yyyy}"></e-column>
        </e-columns>
    </ej-grid>

</div>

When i switch from the ODataV4 to WebApi the result is good.

Thanks in advance
Stefano Capobianco


3 Replies

KM Kuralarasan Muthusamy Syncfusion Team June 11, 2018 04:15 PM UTC

Hi Stefano, 

Thanks for contacting Syncfuion support. 

According to your query you have mention that the issue “TypeError: this.model.CurrentViewData is undefined" occur while using OdataV4Adaptor in Grid. In your given code example we found that you have return the data in form of Items and Count using the PageResult. For WebApiAdaptors only we need to return in the form of Items and Count from server side but for ODataV4Adaptor we need to return in the form of result and count from the server side. We suspect that the mention issue is occur when we return the data in form of Items and count. This may be the root cause of your issue. So, we suggest you to return the data in form of result and count. 

Refer the below code example. 

[OrdersController.cs] 

        [EnableQuery] 
        public IQueryable<Order> Get(ODataQueryOptions opts) 
        { 
            
 
            return db.Orders; 
 
        } 


Refer the screen shot. 

 

 

Regards, 
Kuralarasan M. 



SC Stefano Capobianco June 13, 2018 05:30 AM UTC

Thanks guys, your solution work very well.

Stefano


SE Sathyanarayanamoorthy Eswararao Syncfusion Team June 14, 2018 03:13 PM UTC

Hi Stefano, 

We are happy to hear that your issue has been resolved. 
If you need any further assistance please get back to us. 

Regards, 
Sathyanarayanamoorthy 


Loader.
Up arrow icon