how to know if I'm in the first or last row of a grid

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>


Attachment: 20250524_095927_ec6e2a6b.png

4 Replies 1 reply marked as answer

NP Naveen Palanivel Syncfusion Team May 27, 2025 12:25 PM UTC

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


Marked as answer

SR Sandro Rizzetto May 29, 2025 06:52 AM UTC

Thanks a lot, works perfectly



JS jack smith May 29, 2025 01:44 PM UTC


# 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/

.



NP Naveen Palanivel Syncfusion Team June 2, 2025 03:03 AM UTC

Hi Sandro,


Kindly get back to us if you have further queries. As always we will be assist you.



Regards,
Naveen


Loader.
Up arrow icon