Angular grid not populated by datamanager

Hello I have a grid that was populated by a simple httpget request to my Web api (dotnet core 2.1).
I tried implementing a datamanager but I don't get any data back.
This is my code: 
Controller:
      [HttpGet]
public async Task<ActionResult<dynamic>> GetAll()
{

var items = await base._unitOfWork.Products.GetAsync();
if (items.Any()) {
dynamic retVal = new System.Dynamic.ExpandoObject();
retVal.items = _mapper.Map<IEnumerable<ProductDTO>>(items);
retVal.count = items.Count();
return Ok(retVal);
}
return NoContent();
}
Angular component
ngOnInit(): void {
this.data = new DataManager({
url: 'https://localhost:5001/api/Product',
adaptor: new WebApiAdaptor
});
     }


1 Reply

MF Mohammed Farook J Syncfusion Team July 18, 2018 12:09 PM UTC

Hi Alberto, 

Thanks for contacting Syncfusion support.  


We have validated the provided code example and we suspect that return items and count as incorrect.  The WebApiAdaptor expects the response with properties { Items, Count }.You need to update in your code as Items(I as capital) and Count(C as capital). Please find the code example and  sample for your reference. 

[component.ts]  

@Component({  
    selector: 'fetchdata',  
    template: '<ejs-grid [dataSource]='data' [allowPaging]='true' [allowSorting]="true"[allowFiltering]='true' height='273px'>  
    .  .  .  
</ejs-grid>'  
})  
export class FetchDataComponent {  
    public data: DataManager;  
  
    ngOnInit(): void {  
        this.data = new DataManager({  
            url: '/api/Orders/',  
            adaptor: new WebApiAdaptor,  
        });  
          
    }  
}  



[OrdersController]  


public object Get() 
        { 
            var data = OrdersDetails.GetAllRecords().ToList(); 
            return new { Items = data, Count = data.Count() }; 
        } 





Regards, 
J Mohammed Farook 
 


Loader.
Up arrow icon