Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display row number in MVC WebGrid

I want to have a column as row number in MVC WebGrid. How can I do it?

like image 818
M.Azad Avatar asked Nov 28 '22 11:11

M.Azad


1 Answers

That's a really nice approach, but when you use sorting or paging your RowNumber values won't start from 1 on the page.

In my project I had a case where I needed to know an index of the row independently of WebGrid's paging / sorting and I came across the following solution:

grid.Column(
    Header: "RowNumber",
    Format: item => item.WebGrid.Rows.IndexOf(item) + 1
)
like image 85
takemyoxygen Avatar answered Jan 10 '23 15:01

takemyoxygen