datagrid contextmenu

main
Peace 10 months ago
parent 896e4979bd
commit dbdb7fe193
  1. 4
      ComponentPractice/ComponentPractice/Components/Layout/MainLayout.razor
  2. 2
      ComponentPractice/ComponentPractice/Components/Pages/DataGrid.razor
  3. 2
      ComponentPractice/ComponentPractice/Components/Pages/DataGridAdv.razor
  4. 27
      ComponentPractice/ComponentPractice/Components/Pages/DataGridREST.razor
  5. 2
      ComponentPractice/ComponentPractice/Data/InMemoryData.cs
  6. 2
      ComponentPractice/ComponentPractice/Models/Employee.cs

@ -14,8 +14,6 @@
@Body @Body
</article> </article>
</main> </main>
<RadzenComponent />
</div> </div>
<div id="blazor-error-ui"> <div id="blazor-error-ui">
@ -23,3 +21,5 @@
<a href="" class="reload">Reload</a> <a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a> <a class="dismiss">🗙</a>
</div> </div>
<RadzenComponents @rendermode="RenderMode.InteractiveServer"/>

@ -26,7 +26,7 @@
<RadzenDataGridColumn Property="@nameof(Employee.City)" Title="City" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.City)" Title="City" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Region)" Title="Region" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.Region)" Title="Region" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.PostalCode)" Title="PostalCode" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.PostalCode)" Title="PostalCode" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.County)" Title="County" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.Country)" Title="County" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Phone)" Title="Phone" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.Phone)" Title="Phone" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Extension)" Title="Extension" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.Extension)" Title="Extension" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Notes)" Title="Notes" Width="300px" /> <RadzenDataGridColumn Property="@nameof(Employee.Notes)" Title="Notes" Width="300px" />

@ -34,7 +34,7 @@
<RadzenDataGridColumn Property="@nameof(Employee.City)" Title="City" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.City)" Title="City" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Region)" Title="Region" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.Region)" Title="Region" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.PostalCode)" Title="PostalCode" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.PostalCode)" Title="PostalCode" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.County)" Title="County" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.Country)" Title="County" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Phone)" Title="Phone" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.Phone)" Title="Phone" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Extension)" Title="Extension" Width="160px" /> <RadzenDataGridColumn Property="@nameof(Employee.Extension)" Title="Extension" Width="160px" />
<RadzenDataGridColumn Property="@nameof(Employee.Notes)" Title="Notes" Width="300px" /> <RadzenDataGridColumn Property="@nameof(Employee.Notes)" Title="Notes" Width="300px" />

@ -3,6 +3,7 @@
@using System.Linq.Dynamic.Core @using System.Linq.Dynamic.Core
@inject NorthwindDataService service; @inject NorthwindDataService service;
@inject ContextMenuService contextMenuService;
@rendermode RenderMode.InteractiveServer @rendermode RenderMode.InteractiveServer
@ -30,9 +31,10 @@
</RadzenCard> </RadzenCard>
<RadzenCard class="rz-p-12" Style="width: 900px"> <RadzenCard class="rz-p-12" Style="width: 900px">
<RadzenText TextStyle="TextStyle.H5">DataGrid <strong>Virtualization</strong></RadzenText> <RadzenText TextStyle="TextStyle.H5">DataGrid <strong>Virtualization & ContextMenu</strong></RadzenText>
<RadzenDataGrid Data="@vtzdCustomers" Style="height:500px" <RadzenDataGrid TItem="@Customer" Data="@vtzdCustomers" @bind-Value="selectedVtzdCustomers" Style="height:500px"
CellContextMenu="@OnCellContextMenu"
AllowVirtualization="true" AllowVirtualization="true"
SelectionMode="DataGridSelectionMode.Single" SelectionMode="DataGridSelectionMode.Single"
AllowFiltering="true" AllowColumnResize="true" AllowAlternatingRows="false" FilterMode="FilterMode.CheckBoxList" AllowSorting="true"> AllowFiltering="true" AllowColumnResize="true" AllowAlternatingRows="false" FilterMode="FilterMode.CheckBoxList" AllowSorting="true">
@ -49,10 +51,10 @@
<RadzenDataGridColumn Property="@nameof(Customer.Fax)" Filterable="true" Title="Fax" Width="160px" TextAlign="TextAlign.Center" /> <RadzenDataGridColumn Property="@nameof(Customer.Fax)" Filterable="true" Title="Fax" Width="160px" TextAlign="TextAlign.Center" />
</Columns> </Columns>
</RadzenDataGrid> </RadzenDataGrid>
<RadzenText TextStyle="TextStyle.Body1" Text="@message"/>
</RadzenCard> </RadzenCard>
@code { @code {
readonly int PAGE_SIZE = 10; readonly int PAGE_SIZE = 10;
@ -94,10 +96,27 @@
// Virtualization // Virtualization
IEnumerable<Customer> vtzdCustomers; IEnumerable<Customer> vtzdCustomers;
IList<Customer> selectedVtzdCustomers;
string message = "Message: ";
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
var result = await service.GetCustomer(); var result = await service.GetCustomer();
vtzdCustomers = result.Value; vtzdCustomers = result.Value;
} }
void OnCellContextMenu(DataGridCellMouseEventArgs<Customer> args)
{
selectedVtzdCustomers = new List<Customer>() { args.Data };
contextMenuService.Open(args,
new List<ContextMenuItem> {
new ContextMenuItem(){ Text = "ContextMenuItem 1", Value = 1, Icon = "home" },
new ContextMenuItem(){ Text = "ContextMenuItem 2", Value = 2, Icon = "search" },
new ContextMenuItem(){ Text = "ContextMenuItem 3", Value = 3, Icon = "info" },
},
e => {
message = $"Message: Menu item cliked! Value={e.Value} | Column: {args.Column.Property} | CustomerID: {args.Data.CustomerID}";
InvokeAsync(StateHasChanged);
});
}
} }

@ -33,7 +33,7 @@ namespace ComponentPractice.Data
City = cities[random.Next(cities.Length)], City = cities[random.Next(cities.Length)],
Region = regions[random.Next(regions.Length)], Region = regions[random.Next(regions.Length)],
PostalCode = $"{random.Next(10000, 99999)}", PostalCode = $"{random.Next(10000, 99999)}",
County = counties[random.Next(counties.Length)], Country = counties[random.Next(counties.Length)],
Phone = $"{random.Next(100, 999)}-555-{random.Next(1000, 9999)}", Phone = $"{random.Next(100, 999)}-555-{random.Next(1000, 9999)}",
Extension = $"{random.Next(100, 9999)}", Extension = $"{random.Next(100, 9999)}",
Notes = "Generated demo data" Notes = "Generated demo data"

@ -14,7 +14,7 @@
public string City { get; set; } public string City { get; set; }
public string Region { get; set; } public string Region { get; set; }
public string PostalCode { get; set; } public string PostalCode { get; set; }
public string County { get; set; } public string Country { get; set; }
public string Phone { get; set; } public string Phone { get; set; }
public string Extension { get; set; } public string Extension { get; set; }
public string Notes { get; set; } public string Notes { get; set; }

Loading…
Cancel
Save