DataGrid Paging not working with our Custom Method

Hi, we created a custom method and when invoke the custom method the datagrid loads the data ok, but we have no paging available with it. We would like paging to work with our custom method.
This is the Code in the ServerMethodsController.cs

[Microsoft.AspNetCore.Authorization.Authorize(AuthenticationSchemes="Bearer")]
[EnableQuery(MaxExpansionDepth=10,MaxAnyAllExpressionDepth=10,MaxNodeCount=1000)]
[HttpGet]
public IActionResult GetAllSupaliPatients()
{

AuthController.AddTokenToHeader(this.HttpContext).Wait();
var items = this.context.SupaliPatients.AsQueryable<Models.SupAli.SupaliPatient>();

return Json(new { value = items }, new JsonSerializerSettings() { ContractResolver = new DefaultContractResolver() });
}

You need return also the total records count and to assign the value to Count property of the DataGrid.

We do seem to have the count tied to the datagrid count and we see that we get 688 records back.
However we know we do not have the typical event.skip and event.top, parameters available to set like with the odata call we use in another similar datagrid.

According to the code in your first post there is no total count returned by your custom method.

How can that be done, my return value is the list of patients, how do I return two values, are you saying I need to modify my json thats returned somehow with a count tag?

Also we reduced our count property statement for the page property getAllSupAliPatientsCount, which as I said above is bound to the count variable of the datagrid, this got the paging buttons to light up but if you click on any of them nothing happens the same records show, so paging is not working?


Hey @BillP,

The count variable should be populated as I described to work properly. You can return it in the same method however the return type should be something else (your class for example with count and data properties) or you can use separate method.

You can also try the approach described here:

Just return IQueryable.

We are getting the length/count correctly into the getAllSupAlipatientsCount page property which is bound to the Datagrid count. Are you saying that isn't working?

will also look into that link you gave

The DataGrid will attempt to perform OData query in the way you've setup it while your server method will not work like OData in the current version of your code.

I'll try to explain again:

  • If you want server paging you need to make your custom method work like OData method
  • if you need in-memory client-side paging, just return the data from your server method in Page Load and assign it to the grid Data property. You do not need LoadData or Count.

Yes I was hoping you could provide example code for this in a custom method to speed this up as paging is such a ubiquitous requirement for data grids. We will have tens of thousands of records so we need the paging, not in memory solution.
Are you saying also that the example in the link you sent above will work with the angular datagrid for paging?

Here is an example demonstrating the approach from the link I posted:

To force ServerMethodsController to work like ODataController (to have $skip, $top, etc. parameters) you need to execute builder.EnableDependencyInjection(); in Startup.Configure() method when describing routes:

You need to add Startup.cs to the application ignore list or wait for our next update where it we will expose additional partial method for such configurations.

Other approach is to use ServerMethodsController like normal MVC controller. In this case there will be no $skip, $top, etc. OData like parameters and you should provide them as normal parameters like in our documentation:

Thank you very much, we will give this a try.
Do we edit directly our pages json loaddata section like you've hi-lighted in your main-page.json, if we do edit that directly is that file something we have to add to the exclude list in radzen?

If you plan to take the route of forcing ServerMethodsController to work like ODataController you will need to specify the parameters type directly in the meta json since the Radzen UI does not work out of the box this way. If you choose the second approach you can use Radzen UI to specify parameters normally. Code generation ignore list works with the code generated from meta, it’s not related to the meta itself.

Thank you very much, we'll get back to you and let you know in a day our so how it works out for us (we will try the option of forcing ServerMethodsController to work like ODataController).

That worked, we have paging now, thanks?

We notice the column sorting, does not work though?

Here is how to enable filtering and sorting as well: