Filter grid by query string or same effect

Is there a way to filter a RadzenDataGrid by query string or something of the same effect?

I have one grid that each row has a RadzenLink to another page in the application, I want that link to pass an Id and have the destination page filter by that Id

Check how our CRUD pages are passing the Id of the record from view page with the DataGrid to the edit page - parameter is declared in @page directive in the razor file and there is a property with the same name in the C# file.

Hi Chad,
i'm not the top blazor or radzen expert, but for me this works perfect:

  1. I create a service with a class inside with a lot of variables and dictonaries. There i store different ID's for the grid or forms as 'load-filter' and 'lookup'-tables for the comboboxes
  2. On the Click event, i store the necessary values in the service-variables
  3. On the load-event of the new page or dialog, i read this values and bind it to the filter of the query

My question to enchev:

  1. If i have some kind of master-detail structure (real depndencies), is it better to open the details in a new page or a dialog?
  2. I inject my lookup-service in each page it use it. On the other hand i must declare each parameter on each page. With a view of 'ressource use', what is the better way?

Hope my explanation sounds not to strange.

Patric

I do not see how the @page comes into play as far as a parameter.

I do see how the edit row works though, it uses the DialogService to open the edit page. I'm already doing something similar without args because I just need the Id

<RadzenDataGridColumn TItem="RadzenBlazorServerApp.Models.sql_database.Load" Property="Truck.NameNum" Title="Truck">
   <Template Context="load">
      @{
          if (load.Truck != null)
          {
              <RadzenButton Variant="Variant.Text" Click=@(args => EditTheTruck(load.Truck.Id)) Text="@load.Truck.NameNum" ButtonStyle="ButtonStyle.Primary" />
          }
      }
   </Template>
</RadzenDataGridColumn>

and in the c#

protected async Task EditTheTruck(int Id)
{
    await DialogService.OpenAsync<EditTruck>("Edit Truck", new Dictionary<string, object> { { "Id", Id } });
}

So my question now is how do I just go to a different page vs it being a diaglog box?

Can you use a parameter with RadzenLink?

You need to use navigate to page instead dialogs to see how parameters are defined:



Got it working, needed to use NavigationManager.

Starting point was this in the starting grid (Click attribute gets me to the code behind)

<RadzenDataGridColumn TItem="RadzenBlazorServerApp.Models.sql_database.Load" Property="AltLoadNameNum" Title="Load" Frozen="true">
    <Template Context="load">
        @load.AltLoadNameNum (<RadzenButton Variant="Variant.Text" Click=@(args => VehiclesFiltered(load.Id)) Text="@load.Vehicles.Count().ToString()" ButtonStyle="ButtonStyle.Primary" Size="ButtonSize.ExtraSmall" />)
    </Template>
</RadzenDataGridColumn>

Starting Grid code behind

protected async Task VehiclesFiltered(int LoadId)
{
    NavigationManager.NavigateTo($"vehicles/{LoadId}");
}

Receiving Page (note you can have multiple @page directives, essentially multiple routes)

@page "/vehicles"
@page "/vehicles/{LoadId:int}"

Receiving page code behind

[Parameter]
public int LoadId { get; set; }

Also in receiving page code behind (when you go to "/vechicles" LoadId is 0 because int initializes to 0)

if (LoadId == 0)
    vehicles = vehicles.Where(x => x.TenantId == Security.User.TenantId);
else
    vehicles = vehicles.Where(x => x.TenantId == Security.User.TenantId && x.LoadId == LoadId);

Thanks for the response.

I think by using the built in NavigationManager I saved having to write my own service.

I’m trying to code as little as possible by leveraging Radzen whenever possible