Row number in Datagrid

Is there a possibility to display a row number for each row in the datagrid, which isn't bound to the index of the property? When the number is bound to the index like this, its changing when filters are applied or data is sorted. I need a number which is not dependent on the data.

The index of the item of the collection is exactly what you are looking for since it will always start from 0 doesn’t matter filtering and sorting.

please tell me how to do it right. the numbers in the first colums are always mixed up as shown in the picture above as soon as I filter or sort.
my code at the moment:

<RadzenDataGrid @ref="@DataGrid" Data="@ListOfTubes" TItem="Tube" AllowFiltering="true" PageSize="50" AllowPaging="true" AllowSorting="true" FilterMode="FilterMode.Advanced" AllowColumnResize="true" FilterPopupRenderMode="PopupRenderMode.OnDemand">
	<Columns>
		<RadzenDataGridColumn Width="50px" TItem="Tube" Title="#" Filterable="false" Sortable="false" TextAlign="TextAlign.Center">
			<Template Context="data">
				@(ListOfTubes.IndexOf(data) + 1)
			</Template>
		</RadzenDataGridColumn>
 ...
   </Columns>
 </RadzenDataGrid>

You can use @DataGrid.View as collection.

thanks a lot for the fast help!

got it work with

@(DataGrid.View.ToList().IndexOf(data) + 1)

I’ve updated this demo with more efficient approach to get the current row index:

1 Like

Ran into a problem with your example: Blazor DataGrid footer totals

I set PageSize="10" right on the demo site and the line numbering changes each time when you click on a line in the table.
Why there is a re-rendering of the table for each click :thinking:

chrome_2023-07-07_17-16-56

And I'm looking for a way to properly number rows when using IQueryable and LoadData.
Who has a working method?

This is definitely undesired - we will fix the demo.

if (_rowNumber >= DataGrid.PageSize || DataGrid.CurrentPage * DataGrid.PageSize + _rowNumber >= _count)
					{
						_rowNumber = 0;
					}

Temporary fix, while waiting for the re-render fix. Suddenly someone will come in handy

Any info on the fix?

chrome_2023-08-17_13-04-50

I’ve updated the demo.

Thx.
I didn't know about RenderOnceComponent

It’s a custom component I’ve made for this demo - check the source code in the extra tab.