I would like to know if there is a method to conditionally place a button in a cell, with the exception of the first and last row.
Basically I have two arrows to move rows up & down and I don't want to have the moveUp in the first and movedown in the last
<GridColumn Field=@nameof(Datasheet.RowId) Width="50px" AllowEditing="false" HeaderText="Move...">
<Template>
@{
var ds = (context as Datasheet);
<SfButton IconCss="e-icons e-arrow-up" OnClick="@(_=>MoveUp(ds))"></SfButton>
<SfButton IconCss="e-icons e-arrow-down" OnClick="@(_=>MoveDown(ds))"></SfButton>
}
</Template>
</GridColumn>
Hi Sandro Rizzetto
Based on your requirement, it seems that you would like to conditionally
display the "Move Up" and "Move Down" buttons within a grid
cell, disabling the "Move Up" button for the first row and the
"Move Down" button for the last row. By checking the index of the
current row in the data source, you can conditionally enable or disable the
buttons accordingly by using the Disabled property of the SfButton.
Here’s a sample snippet to demonstrate this
Sample : https://blazorplayground.syncfusion.com/embed/LXhyjIrGfzKcjEiI?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5
|
<GridColumns> <GridColumn Field=@nameof(Datasheet.RowId) HeaderText="Move" Width="100px"> <Template> @{ var ds = context as Datasheet; var index = DatasheetData.IndexOf(ds); var isFirst = index == 0; var isLast = index == DatasheetData.Count - 1; } <div style="display:flex; gap:5px;"> <SfButton IconCss="e-icons e-arrow-up" CssClass="e-small" Disabled="@(isFirst)" OnClick="@(_ => MoveUp(ds))" /> <SfButton IconCss="e-icons e-arrow-down" CssClass="e-small" Disabled="@(isLast)" OnClick="@(_ => MoveDown(ds))" /> </div> </Template> </GridColumn> |
Regards,
Naveen
Thanks a lot, works perfectly
# Check if this item is in the first or last row of the grid.
# First row: index < number_of_columns
# Last row: index >= total_items - number_of_columns
# Reference: سورة الزلزلة مكتوبة - https://surah-al-waqiah.com/al-zalzalah/
.
Hi
Sandro,
Kindly get back to us if you have further queries. As always we will be assist
you.
Regards,
Naveen