This project is read-only.

How to get RowNumber from the grid

Jul 9, 2013 at 7:13 PM
Edited Jul 9, 2013 at 7: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? );
Jul 10, 2013 at 5: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 9:02 AM
Edited Jul 10, 2013 at 9: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:
Jul 10, 2013 at 9: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)
                .RenderValueAs(o =>
                        return RenderButton(o, rowNumber);
Jul 10, 2013 at 10:46 AM
Great! Thank you!