Strange behavior of DataGrid with stored procedure

Hi,
i work on an asp.net core hosted blazor wasm (.Net 7.0.16).
I had a page with a RadzenDataGrid generated from Blazor Studio and bind to a SqlServer table. I use paging, sorting and filtering; all working as expected.

Now i create a stored procedure (SP), that combine some columns and replace foreign keys with the values of the lookup tables, since the grid is for 'Readonly'. I use a parameter as 'filter' for the SP, that in the former version was used as a 'odata filter'

former version:
protected IEnumerable<MyAdmino.Server.Models.MyAdminoDB.TPersonenliste> tPersonenlistes;
protected RadzenDataGrid<MyAdmino.Server.Models.MyAdminoDB.TPersonenliste> grid0;

sFilter = "(aktiv eq true) and (Mandantrefnr eq " + tMandanten.MandRefnr.ToString() + ")";
var result_Kontakt = await MyAdminoDBService.GetTPersonenlistes(filter: sFilter, orderby: $"PersRefnr desc", top: args.Top, skip: args.Skip, count: args.Top != null && args.Skip != null);
tPersonenlistes = result_Kontakt.Value.AsODataEnumerable();
count_Kontakt = result_Kontakt.Count;

new version:

protected RadzenDataGrid<MyAdmino.Server.Models.MyAdminoDB.PLadePersonListe> grid0;
public IEnumerable Person_Liste;

var Pers = await MyAdminoDBService.PLadePersonListesFunc(tMandanten.MandRefnr);
Person_Liste = Pers.Value.AsODataEnumerable();
count_Kontakt = Pers.Count;

I created a model for the SP and bind it to the Datagrid

If i use the new version with the SP the data is loaded and shown, but there is no paging, no filtering and no sorting!

Any idea what i do wrong??

Thanks for help

Patric

Try to format your code, it’s very hard to read anything at the moment.

Sorry, i copy and paste from VS2022; but all 'format info' (color, ...) is lost on paste:

old version (do all right):
Variables:
protected IEnumerable<MyAdmino.Server.Models.MyAdminoDB.TPersonenliste> tPersonenlistes;
protected RadzenDataGrid<MyAdmino.Server.Models.MyAdminoDB.TPersonenliste> grid0;
protected int count_Kontakt;

LoadData event
protected async Task Grid0LoadData(LoadDataArgs args)
{
IsLoading = true;
try
{
sFilter = "(aktiv eq true) and (Mandantrefnr eq " + tMandanten.MandRefnr.ToString() + ")";
var result_Kontakt = await MyAdminoDBService.GetTPersonenlistes(filter: sFilter,
orderby: $"PersRefnr desc", top: args.Top, skip: args.Skip, count: args.Top != null
&& args.Skip != null);
tPersonenlistes = result_Kontakt.Value.AsODataEnumerable();
count_Kontakt = result_Kontakt.Count;
IsLoading = false;
}
catch (System.Exception ex)
{
IsLoading = false;
NotificationService.Notify(new NotificationMessage() { Severity = NotificationSeverity.Error,
Summary = $"Error", Detail = ex.Message + $" Fehler beim Laden der Ansprechpartner!" });
}
}

Page:

and so on

New Version:
Variables:
public IEnumerable Person_Liste;
protected RadzenDataGrid<MyAdmino.Server.Models.MyAdminoDB.PLadePersonListe> grid0;
protected int count_Kontakt;

LoadData event
protected async Task Grid0LoadData(LoadDataArgs args)
{
IsLoading = true;
try
{
var Pers = await MyAdminoDBService.PLadePersonListesFunc(iMand_ID);
Person_Liste = Pers.Value.AsODataEnumerable();
count_Kontakt = Pers.Count;
IsLoading = false;
}
catch (System.Exception ex)
{
IsLoading = false;
NotificationService.Notify(new NotificationMessage() { Severity = NotificationSeverity.Error,
Summary = $"Error", Detail = ex.Message + $" Fehler beim Laden der Ansprechpartner!" });
}
}

Page:

and so on...

I think the problem is that the result set of the SP is on the client and i miss the way to page, filter and sort on the 'client-collection'. So your datagrid need 'filter: sFilter, orderby: $"PersRefnr desc", top: args.Top, skip: args.Skip' parameter. But how can i set this on the result of a SP?

Thanks for help!
Patric

Sorry, i try to format my code with 'return's and blanks, but on 'save' they are gone away!!!

Check our forum FAQ!

Hi enchev,
ok, i found this link

and add these code in my LoadData-event

    protected async Task Grid0LoadData(LoadDataArgs args)
    {
        IsLoading = true;
        try
        {
            var Pers = await MyAdminoDBService.PLadePersonListesFunc(iMand_ID);
            count_Kontakt = Pers.Count;
            Person_Liste_Temp = Pers.Value.AsQueryable();
            if (!string.IsNullOrEmpty(args.Filter))
            {
                // Filter via the Where method
                Person_Liste_Temp = Person_Liste_Temp.Where(args.Filter);
            }

            if (!string.IsNullOrEmpty(args.OrderBy))
            {
                // Sort via the OrderBy method
                Person_Liste_Temp = Person_Liste_Temp.OrderBy(args.OrderBy);
            }
            // Perform paging via Skip and Take.
            Person_Liste = Person_Liste_Temp.Skip(args.Skip.Value).Take(args.Top.Value).ToList();

            IsLoading = false;
        }
        catch (System.Exception ex)
        {
            IsLoading = false;
            NotificationService.Notify(new NotificationMessage() { Severity = NotificationSeverity.Error, 
            Summary = $"Error", Detail = ex.Message + $" Fehler beim Laden der Ansprechpartner!" });
        }
    }

Now sorting and filtering works; AllowPaging="true" PageSize=10 show only 10 rows in the grid!

But the pager controll itself is not shown!!

Any idea how to fix??

Thanks

Patric

You need to set Count, check our demos for reference.

Hi enchev,

your hint push me in the right direction!!

var Pers = await MyAdminoDBService.PLadePersonListesFunc(iMand_ID);
-- here i load the data from the SP
count_Kontakt = Pers.Count;
-- here i set the number of rows i though; but as i must see Pers.Count = 0!!!

Person_Liste_Temp = Pers.Value.AsQueryable();
-- here i load my data realy!!
count_Kontakt = Person_Liste_Temp.Count();
-- and now count_Kontakt got the number of rows in the collection (attention: you must use the method count() not the field 'Count'!!)

Now all works as in the old version!

Thanks for your help and sorry that i not found the solution in the beginning!

To summarize (if someone had similar problems):

In the LoadData-event of the Datagrid catch the 'LoadDataArgs args' and handle 'args.Filter', 'args.OrderBy' and paging via 'Skip(args.Skip.Value).Take(args.Top.Value).ToList()'.

And be sure to set 'count' correct!!

Again, thanks for your support!!

Patric