<SfGrid DataSource="@Orders" AllowPaging="true" Height="315">
<GridEvents RowDataBound="RowBound" TValue="Order"></GridEvents>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
. . . . . .
<GridColumn HeaderText="Manage Records" Width="150">
. . . . . . . .
</GridColumn>
</GridColumns>
</SfGrid>
<style>
.e-removecommand .e-unboundcell .e-unboundcelldiv button {
display: none;
}
</style>
@code{
public List<Order> Orders { get; set; }
public void RowBound(RowDataBoundEventArgs<Order> Args)
{
if (Args.Data.Verified)
{
Args.Row.AddClass(new string[] { "e-removecommand" });
}
}
|
|
<SfGrid DataSource="@Orders" AllowPaging="true" Height="315">
<GridEvents RowDataBound="RowBound" TValue="Order"></GridEvents>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
<GridColumn Type="ColumnType.CheckBox" Width="50"></GridColumn>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" Format="d" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
<style>
.e-removecheck .e-gridchkbox .e-checkbox-wrapper {
display: none;
}
</style>
@code{
public List<Order> Orders { get; set; }
public void RowBound(RowDataBoundEventArgs<Order> Args)
{
if (Args.Data.Verified)
{
Args.Row.AddClass(new string[] { "e-removecheck" });
}
}
|
<SfGrid DataSource="@Orders" AllowPaging="true" Height="315">
<GridEvents RowDataBound="RowBound" TValue="Order"></GridEvents>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" Format="d" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn HeaderText="Manage Records" Width="150">
<GridCommandColumns>
<GridCommandColumn Type="CommandButtonType.Edit" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-edit", CssClass = "e-flat" })"></GridCommandColumn>
<GridCommandColumn Type="CommandButtonType.Delete" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-delete", CssClass = "e-flat" })"></GridCommandColumn>
<GridCommandColumn Type="CommandButtonType.Save" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-update", CssClass = "e-flat" })"></GridCommandColumn>
<GridCommandColumn Type="CommandButtonType.Cancel" ButtonOption="@(new CommandButtonOptions() { IconCss = "e-icons e-cancel-icon", CssClass = "e-flat" })"></GridCommandColumn>
</GridCommandColumns>
</GridColumn>
</GridColumns>
</SfGrid>
<style>
/*to remove the edit button alone*/
.e-removeEditcommand .e-unboundcell .e-unboundcelldiv button.e-Editbutton {
display: none;
}
/*to remove the delete button alone*/
.e-removeDeletecommand .e-unboundcell .e-unboundcelldiv button.e-Deletebutton {
display: none;
}
</style>
@code{
public List<Order> Orders { get; set; }
public void RowBound(RowDataBoundEventArgs<Order> Args)
{
if (Args.Data.Verified)
{
Args.Row.AddClass(new string[] { "e-removeEditcommand" });
}
else
{
Args.Row.AddClass(new string[] { "e-removeDeletecommand" });
}
}
|
This only hides the command buttons but the buttons are still there for anyone to mess with.
Is there a way to actually remove a button depending on the data of the row?
How do we do this (hide the command button) for custom command action? (aka CommandButtonType.None)
I have a Manage Record column with a few custom command buttons (CommandButtonType.None). I'm not sure how I can attach the class to the correct one. I review the html and see there's a e-none but that won't work.
<SfGrid DataSource="@Orders" AllowPaging="true" Height="315">
<GridEvents RowDataBound="RowBound" TValue="Order"></GridEvents>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" EditType="EditType.DatePickerEdit" Format="d" TextAlign="TextAlign.Right" Width="130"></GridColumn>
<GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn HeaderText="Manage Records" Width="150">
<GridCommandColumns>
<GridCommandColumn Type="CommandButtonType.None" ButtonOption="@(new CommandButtonOptions() { Content = "Details", CssClass = "e-flat e-details" })"></GridCommandColumn>
<GridCommandColumn Type="CommandButtonType.None" ButtonOption="@(new CommandButtonOptions() { Content = "Content", CssClass = "e-flat e-btn-content" })"></GridCommandColumn>
</GridCommandColumns>
</GridColumn>
</GridColumns>
</SfGrid>
<style>
/*to remove the specific edit button alone*/
.e-removeEditcommand .e-unboundcell .e-unboundcelldiv button.e-details {
display: none;
}
/*to remove the specific content button alone*/
.e-removeDeletecommand .e-unboundcell .e-unboundcelldiv button.e-btn-content {
display: none;
}
</style>
@code{
public List<Order> Orders { get; set; }
public void RowBound(RowDataBoundEventArgs<Order> Args)
{
//based on your requirement you can add the class to specific records.
if (Args.Data.Verified)
{
Args.Row.AddClass(new string[] { "e-removeEditcommand" });
}
else
{
Args.Row.AddClass(new string[] { "e-removeDeletecommand" });
}
}
|
Hi Vignesh,
your examples above for removing buttons with css works fine, but there is Backdoor for the standard Edit Button. Because of the GridEditSettings AllowEditOnDblClick Parameter you can edit the row, even you removed the edit button with css.
So the question is how can i prevent editing the row by DblClick?
Simple Answer: Just set AllowEditOnDblClick=false, yeah i know, but it's a nice feature and i don't wanna miss it.
Maybe it's also a way with css? sort of e-row-readonly?
Regards
S
Hi Stefan,
Greetings from Syncfusion.
Query: So the question is how can i prevent editing the row by DblClick?
We suggest you to use the AllowEditOnDblClick property of the GridEditSettings. Find the below code snippets for your reference.
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" AllowEditOnDblClick="false"></GridEditSettings> |
Since we already have an option to disable this behavior(Edit on double click), we suggest you to use this way to achieve your requirement.
Please let us know if you have any concerns.
Regards,
Rahul
Thanks Rahul, i was afraid you saying that. I think i'll can live with it.
Regards
Stefan
Hi Stefan,
Thanks for the update.
Please get back to us if you need further assistance.
Regards,
Rahul