Datagrid loaded conditionally

#1

Hello,
I have a page with a datagrid generated with Radzen scaffolding.
I need to load the same datagrid with two differents set of data depending on a checkbox state:

  • the table X;
  • the view Y with same columns of table X but less rows;

Both X and Y have one to many relationships with other tables.
I supposed I can do this in the checkbox change event:

  • depending on checkbox state
  • invoke right datasource
  • set getXResult and getXcount
  • execute this.grid0.load()

I supposed also I can copy steps directly from datagrid loaddata event.

Unfortunately it seems it is not working, I see query are executed but I do not see the query on the view.
Am I following the right path? Can you give me some hints ?
Thanks,
Mario

0 Likes

#2

Actually it seems that if in the datagrid (created automatically for table X) I try to load view Y (same columns) it shows no rows.

0 Likes

#3

Ok I have discovered the problem and it is a big blocking one.
Your code generator for class X has generated a model with correct ForeignKey attributes.
Unfortunately for view Y has generated a model with no attributes even if the view has foreign keys relationships.
How can I save this situation?

0 Likes

#4

Please send us your database schema at info@radzen.com with more info which relation is not generated correctly.

0 Likes

#5

I will do.
I add that putting in the same script two "invoke datasource" (with condition) seems to confuse/break the "create query" gui in parameters section. I cannot set different filters for the two "invoke datasource".
Is it possible?

0 Likes

#6

Do you have any exception? Can you post a screenshot?

0 Likes

#7

Sent just now. Thanks.

0 Likes

#8

I can describe behaviour. The first "invoke datasource" has a filter defined, the second is empty.
If I go in first one and in "create query" I see the filter, then I go in to the second "create query" and I see the same filter (it should be empty).
If I do the reverse all is empty also the first one.
It does not do this all times I try.

0 Likes

#9

Indeed this sounds like a bug. We will check it and will include fix in our next release.

0 Likes

#10

Hi @mgiammarco,

I've checked your schema and I've realized that you are referring to SQL Views. Radzen can retrieve and work with relationships between SQL tables only.

0 Likes

#11

Very bad news for me.
I hope in the future you will add this feature.

0 Likes

#12

We will do our best to add it as soon as we can! In the meantime the only workaround I can suggest is to construct queries with $filter using Query Builder to retrieve related records between tables and views.

0 Likes

#13

I was doing the "hard way" using a custom method inside ServerMethodController.
In this case I am blocked because ServerMethodController inherits from Controller and I need to inherit from ODataController to have pagination and other features (I suppose... I am newbie in dotnet).
But then you suggest me to "construct queries with $filter".
My problem infact is really simple, in filter I have:

Reparto/Ruolo eq '${security.user.roles[0]}'

And in the model of the database view I have no foreignkey relationship for reparto and ruolo.
Is it possible to modify the filter to manually specify relationships?

0 Likes

#14

Ok as a workaround I created to new views with left join so I have all fields I need without needs to do joins using filters.
Anyway I am interested to know:

  1. if I can used OData in ServerMethodController
  2. what do you mean in : construct queries with $filter using Query Builder to retrieve related records between tables and views.

Thanks again,
Mario

0 Likes

#15

Hi Mario,

Straight to your questions:

  1. You cannot use OData with custom server-methods
  2. Here is an example with Northwind Orders table and Invoices view using partial read method to avoid complex OData queries like in:
    [Authorize(AuthenticationSchemes="Bearer")]
    public partial class OrdersController
    {
        partial void OnOrdersRead(ref IQueryable<Models.Northwind.Order> items)
        {
            var userName = this.HttpContext.User.FindFirst(ClaimTypes.Name).Value;
            var roleName = this.HttpContext.User.FindFirst(ClaimTypes.Role).Value;

            items = items.Where(o => context.Invoices.Where(i => i.OrderID == o.OrderID).Any());
        }
    }

In this case I will return only orders that have invoices. I've added also code to show you how to get user name and role server-side.

Paging, sorting and filtering will work as usual however you will see only filtered orders:

Best Regards,
Vladimir

0 Likes