How to get RowNumber from the grid

Jul 9, 2013 at 6:13 PM
Edited Jul 9, 2013 at 6:13 PM
How to get row number from the grid?

@Html.Grid(Model.c).Columns(columns =>
{
  columns.Add(c =>c.Id);
  columns.Add(c =>c.Name);
  columns.Add(c =>c.Name).RenderValueAs( ?RowNumber? );
}
Coordinator
Jul 10, 2013 at 4:15 AM
Columns adding in order by invoking columns.add method. Now column does not contain rownumber property.
Could you explain the scenario of using RowNumber property?
Jul 10, 2013 at 8:02 AM
Edited Jul 10, 2013 at 8:13 AM
For example I would like to have functional that removes only top one row.
It should be a column delete with control (icon, button etc.)
and this control should be visible depends on row number
and a some property of a Model.

Example image:
Image
http://postimg.org/image/pv6d9tx69/
Coordinator
Jul 10, 2013 at 8:28 AM
The main problem is that now the grid pass only your item to RenderValueAs method without any custom context. But you can solve this problem tby creating custom variable at the top of the view:
@{
    int rowNumber = 0;
}
@helper RenderButton(Order item, int rowNumber)
{
    if (rowNumber == 1)
    {
        <button>Click</button>
    }
}
        columns.Add()
                .Titled("")
                .Sanitized(false)
                .Encoded(false)
                .RenderValueAs(o =>
                    {
                        rowNumber++;
                        return RenderButton(o, rowNumber);
                    });
Jul 10, 2013 at 9:46 AM
Great! Thank you!