|
<button @onclick="OnAddItemButtonPressed">Add Data</button>
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true">
<GridPageSettings PageSize="10"></GridPageSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
. . .
</GridColumns>
</SfGrid>
@code{
SfGrid<Order> Grid;
private int currentId = 123;
public List<Order> Orders { get; set; }
. . .
private void OnAddItemButtonPressed()
{
Order add = new Order();
add.OrderID = currentId;
add.CustomerID = "Tokyo";
add.OrderDate = new DateTime(2020, 04, 05);
add.Freight = 11.22;
Orders.Add(add); //add the created object in Grid datasource. In your code, you have not added the created object in Grid Datasource
Grid.Refresh(); //calling Refresh method of Grid to show the added record
currentId++;
}
} |
|
<SfGrid @ref="Grid" DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" AllowPaging="true">
. . .
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" AllowEditing="false" Width="150"></GridColumn>
. . .
</GridColumns>
</SfGrid> |
|
// Performs Insert operation
public override object Insert(DataManager dm, object value, string key)
{
Orders.Insert(11, value as Order);
return value;
} |
|
<SfButton @ref="ToggleBtn" @onclick="Disable" CssClass="e-flat" IsToggle="true" IsPrimary="true" Content="@Content"></SfButton>
<div class=@ClassValue>
<SfGrid @ref="Grid" DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })" AllowPaging="true">
. . .
</SfGrid>
</div>
@code{
SfButton ToggleBtn;
SfGrid<Order> Grid;
private int currentId = 123;
public string Content = "Disable";
public string ClassValue { get; set; }
. . .
private void Disable(Microsoft.AspNetCore.Components.Web.MouseEventArgs args)
{
if (ToggleBtn.Content == "Disable")
{
ClassValue = "disable"; //here, we have added class to disable
Content = "Enable";
}
else
{
ClassValue = "";
Content = "Disable";
}
}
}
<style>
.disable {
pointer-events: none;
opacity: 0.4;
}
</style> |
|
// Performs Insert operation
public override object Insert(DataManager dm, object value, string key)
{
Orders.Insert(11, value as Order);
return value;
} |
|
public class CustomAdaptor : DataAdaptor
{
[Inject]
public OrderDataAccessLayer context { get; set; } = new OrderDataAccessLayer();
// Performs data Read operation
public override object Read(DataManagerRequest dm, string key = null)
{
IEnumerable<Order> DataSource = context.GetAllOrders();
. . .
return dm.RequiresCounts ? new DataResult() { Result = DataSource, Count = count } : (object)DataSource;
}
} |