|
| 1 | +@page "/datagrid-features" |
| 2 | + |
| 3 | +@using Syncfusion.Blazor.Grids |
| 4 | +@using Syncfusion.Blazor.Calendars |
| 5 | +@using Syncfusion.Blazor.DropDowns |
| 6 | +@using Syncfusion.Blazor.Inputs |
| 7 | +@using System.ComponentModel.DataAnnotations |
| 8 | +<SfGrid DataSource="@GridData" Toolbar="@(new string[] {"Add", "Edit" ,"Delete","Update","Cancel" })"> |
| 9 | + <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="@EditMode.Dialog"> |
| 10 | + <Validator> |
| 11 | + <DataAnnotationsValidator></DataAnnotationsValidator> |
| 12 | + </Validator> |
| 13 | + <Template> |
| 14 | + @{ |
| 15 | + var Order = (context as OrdersDetails); |
| 16 | + <div> |
| 17 | + <ValidationMessage For="() => Order.ShipCountry" /> |
| 18 | + <ValidationMessage For="() => Order.ShipAddress" /> |
| 19 | + <div class="form-row"> |
| 20 | + <div class="form-group col-md-6"> |
| 21 | + <label class="e-float-text e-label-top">Order ID</label> |
| 22 | + <SfNumericTextBox ID="OrderID" @bind-Value="@(Order.OrderID)" Enabled="@((Order.OrderID == null) ? true : false)"></SfNumericTextBox> |
| 23 | + </div> |
| 24 | + <div class="form-group col-md-6"> |
| 25 | + <label class="e-float-text e-label-top">Customer Name</label> |
| 26 | + <SfAutoComplete ID="customerID" TItem="OrdersDetails" @bind-Value="@(Order.CustomerID)" TValue="string" DataSource="@GridData"> |
| 27 | + <AutoCompleteFieldSettings Value="CustomerID"></AutoCompleteFieldSettings> |
| 28 | + </SfAutoComplete> |
| 29 | + </div> |
| 30 | + </div> |
| 31 | + <div class="form-row"> |
| 32 | + <div class="form-group col-md-6"> |
| 33 | + <label class="e-float-text e-label-top">Freight</label> |
| 34 | + <SfNumericTextBox ID="Freight" @bind-Value="@(Order.Freight)" TValue="double?"></SfNumericTextBox> |
| 35 | + </div> |
| 36 | + <div class="form-group col-md-6"> |
| 37 | + <label class="e-float-text e-label-top">Order Date</label> |
| 38 | + <SfDatePicker ID="OrderDate" @bind-Value="@(Order.OrderDate)"></SfDatePicker> |
| 39 | + </div> |
| 40 | + </div> |
| 41 | + <div class="form-row"> |
| 42 | + <div class="form-group col-md-6"> |
| 43 | + <label class="e-float-text e-label-top">Ship Country</label> |
| 44 | + <SfDropDownList ID="ShipCountry" @bind-Value="@(Order.ShipCountry)" TItem="OrdersDetails" TValue="string" DataSource="@GridData"> |
| 45 | + <DropDownListFieldSettings Value="ShipCountry" Text="ShipCountry"></DropDownListFieldSettings> |
| 46 | + </SfDropDownList> |
| 47 | + </div> |
| 48 | + <div class="form-group col-md-6"> |
| 49 | + <label class="e-float-text e-label-top">Ship City</label> |
| 50 | + <SfDropDownList ID="ShipCity" @bind-Value="@(Order.ShipCity)" TItem="OrdersDetails" TValue="string" DataSource="@GridData"> |
| 51 | + <DropDownListFieldSettings Value="ShipCity" Text="ShipCity"></DropDownListFieldSettings> |
| 52 | + </SfDropDownList> |
| 53 | + </div> |
| 54 | + </div> |
| 55 | + <div class="form-row"> |
| 56 | + <div class="form-group col-md-12"> |
| 57 | + <label class="e-float-text e-label-top">Ship Address</label> |
| 58 | + <SfTextBox ID="ShipAddress" @bind-Value="@(Order.ShipAddress)"></SfTextBox> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + } |
| 63 | + </Template> |
| 64 | + </GridEditSettings> |
| 65 | + <GridColumns> |
| 66 | + <GridColumn Field=@nameof(OrdersDetails.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="@TextAlign.Center" HeaderTextAlign="@TextAlign.Center" Width="140"></GridColumn> |
| 67 | + <GridColumn Field=@nameof(OrdersDetails.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> |
| 68 | + <GridColumn Field=@nameof(OrdersDetails.Freight) HeaderText="Freight" Format="C2" Width="140" TextAlign="@TextAlign.Right" HeaderTextAlign="@TextAlign.Right"></GridColumn> |
| 69 | + <GridColumn Field=@nameof(OrdersDetails.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" Width="160"></GridColumn> |
| 70 | + <GridColumn Field=@nameof(OrdersDetails.ShipCountry) HeaderText="Ship Country" Width="150"></GridColumn> |
| 71 | + </GridColumns> |
| 72 | +</SfGrid> |
| 73 | +@code{ |
| 74 | + public List<OrdersDetails> GridData = new List<OrdersDetails> |
| 75 | + { |
| 76 | + new OrdersDetails() { OrderID = 10248, CustomerID = "VINET", Freight = 32.38, ShipCity = "Berlin", OrderDate = DateTime.Now.AddDays(-2), ShipName = "Vins et alcools Chevalier", ShipCountry = "Denmark", ShipAddress = "Kirchgasse 6" }, |
| 77 | + new OrdersDetails() { OrderID = 10249, CustomerID = "TOMSP", Freight = 11.61, ShipCity = "Madrid", OrderDate = DateTime.Now.AddDays(-5), ShipName = "Toms Spezialitäten", ShipCountry = "Brazil", ShipAddress = "Avda. Azteca 123" }, |
| 78 | + new OrdersDetails() { OrderID = 10250, CustomerID = "HANAR", Freight = 65.83, ShipCity = "Cholchester", OrderDate = DateTime.Now.AddDays(-12), ShipName = "Hanari Carnes", ShipCountry = "Germany", ShipAddress = "Carrera 52 con Ave. Bolívar #65-98 Llano Largo" }, |
| 79 | + new OrdersDetails() { OrderID = 10251, CustomerID = "VICTE", Freight = 41.34, ShipCity = "Marseille", OrderDate = DateTime.Now.AddDays(-18), ShipName = "Victuailles en stock", ShipCountry = "Austria", ShipAddress = "Magazinweg 7" }, |
| 80 | + new OrdersDetails() { OrderID = 10252, CustomerID = "SUPRD", Freight = 51.3, ShipCity = "Tsawassen", OrderDate = DateTime.Now.AddDays(-22), ShipName = "Suprêmes délices", ShipCountry = "Switzerland", ShipAddress = "1029 - 12th Ave. S." }, |
| 81 | + new OrdersDetails() { OrderID = 10253, CustomerID = "HANAR", Freight = 58.17, ShipCity = "Tsawassen", OrderDate = DateTime.Now.AddDays(-26), ShipName = "Hanari Carnes", ShipCountry = "Switzerland", ShipAddress = "1029 - 12th Ave. S." }, |
| 82 | + new OrdersDetails() { OrderID = 10254, CustomerID = "CHOPS", Freight = 22.98, ShipCity = "Berlin", OrderDate = DateTime.Now.AddDays(-34), ShipName = "Chop-suey Chinese", ShipCountry = "Denmark", ShipAddress = "Kirchgasse 6" }, |
| 83 | + new OrdersDetails() { OrderID = 10255, CustomerID = "RICSU", Freight = 148.33, ShipCity = "Madrid", OrderDate = DateTime.Now.AddDays(-39), ShipName = "Richter Supermarket", ShipCountry = "Brazil", ShipAddress = "Avda. Azteca 123" }, |
| 84 | + new OrdersDetails() { OrderID = 10256, CustomerID = "WELLI", Freight = 13.97, ShipCity = "Madrid", OrderDate = DateTime.Now.AddDays(-43), ShipName = "Wellington Importadora", ShipCountry = "Brazil", ShipAddress = "Avda. Azteca 123" }, |
| 85 | + new OrdersDetails() { OrderID = 10257, CustomerID = "HILAA", Freight = 81.91, ShipCity = "Cholchester", OrderDate = DateTime.Now.AddDays(-48), ShipName = "HILARION-Abastos", ShipCountry = "Germany", ShipAddress = "Carrera 52 con Ave. Bolívar #65-98 Llano Largo" } |
| 86 | + }; |
| 87 | + public class OrdersDetails |
| 88 | + { |
| 89 | + public int? OrderID { get; set; } |
| 90 | + public string CustomerID { get; set; } |
| 91 | + public double? Freight { get; set; } |
| 92 | + public string ShipCity { get; set; } |
| 93 | + public DateTime OrderDate { get; set; } |
| 94 | + public string ShipName { get; set; } |
| 95 | + [Required] |
| 96 | + public string ShipCountry { get; set; } |
| 97 | + [Required] |
| 98 | + public string ShipAddress { get; set; } |
| 99 | + } |
| 100 | +} |
0 commit comments