Add Column to display Sr.No. in Grid.
I need to print Serial No : 1, Serial No : 2... etc.
but It Started with Serial No : 30
here is my code.
<SfGrid DataSource="@ledgers" AllowPaging="true" AllowSorting="true">
<GridPageSettings PageSize="15"></GridPageSettings>
<GridColumns>
<GridColumn HeaderText="Sr.No" TextAlign="TextAlign.Center" Width="120">
<Template>
@{
<div>Serial No : @RowCount </div>
RowCount++;
}
</Template>
</GridColumn>
<GridColumn Field=@nameof(Ledger.Id) HeaderText="ID" Width="80"></GridColumn>
<GridColumn Field=@nameof(Ledger.Ledgername) HeaderText="Ledger Name"></GridColumn>
<GridColumn Field=@nameof(Ledger.GroupName) HeaderText="Group Name"></GridColumn>
</GridColumns>
</SfGrid>
@code {
private List<Ledger> ledgers { get; set; }
private int RowCount = 0;
protected override async Task OnInitializedAsync()
{
ledgers = await Http.GetFromJsonAsync<List<Ledger>>("api/Ledger/ledgers/1");
}
}
|
<SfGrid DataSource="@Orders" AllowPaging="true">
<GridColumns>
<GridColumn HeaderText="Seerial Number" TextAlign="TextAlign.Center" Width="120">
<Template>
@{
RowCountAI++;
<div>Serial No : @RowCountAI </div>
}
</Template>
</GridColumn>
. . .
</GridColumns>
</SfGrid>
@code{
public List<Order> Orders { get; set; }
public int RowCountAI = 0;
. . .
} |
|
|
- When did you faced this problem? At initial rendering itself or while performing any other operations?
- Reproduce the reported problem in the provided sample and revert back to us.
- Share a simple reproduceable sample if possible.
- Complete code snippets of the page.
No I am also facing the same problem by using above code . I Have Five records and Sno starts from 6 instead of 1
What I mean once all records will be displayed then the series will be generated . In your code it is working fine , In my case data is coming from modal from API
Hi Iram,
Before proceeding with the reporting of the problem, we require some additional clarification from your end. Please share the following details to proceed further on our end.
- To analyze the reported issue, could you please share a simple and reproducible sample with duplicate data that demonstrates the problem? This will assist us in identifying the issue more efficiently and providing a resolution.
- Could you please share us the what the NuGet version you have used?.
The details requested above will be very helpful in validating the reported query on our end and providing a solution as soon as possible. Thanks for your understanding.
Regards,
Prathap Senthil
Here I send an example of the problem where the numbering of rows is not correlative.
<div>
<div style="height: calc(100vh - 7rem);">
<SfGrid DataSource="@datos" @ref="@GridInstance" Height="100%" EnableStickyHeader="true" EnableVirtualization="true" AllowFiltering="true" AllowSorting="true" RowHeight="18" GridLines="GridLine.Both"
AllowSelection="true" AllowResizing="true" EnableHover="true" AllowPaging="true" >
@* <GridEvents OnCellEdit="CellEditHandler" RowSelected="RowSelectedHandler" OnRecordDoubleClick="RecordDoubleClickHandler" OnRecordClick="RecordClickHandler" OnCellSave="OnCellSave" TValue="ListadoAnuncios"></GridEvents> *@
<GridEvents QueryCellInfo="CustomizeCell" RowSelected="RowSelectedHandler" OnRecordDoubleClick="RecordDoubleClickHandler" OnRecordClick="RecordClickHandler" OnCellSave="OnCellSave" TValue="ListadoAnuncios"></GridEvents>
<GridFilterSettings Type=@tipofiltrogrid Mode="FilterBarMode.Immediate" Operators="Operator.Contains" ImmediateModeDelay="@WaitMsecondsBeforeGoSearchByFilter">
@* <GridFilterColumns>
<GridFilterColumn Field="Reference" MatchCase=false Operator="Operator.Contains" Value="a"></GridFilterColumn>
</GridFilterColumns> *@
</GridFilterSettings>
<GridSelectionSettings Type="SelectionType.Multiple" Mode=SelectionMode.Row></GridSelectionSettings>
<GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" Mode="EditMode.Batch" ShowConfirmDialog="false"></GridEditSettings>
<GridColumns>
<GridColumn Field=@nameof(Anuncio.Id_Tbl_Entradas) HeaderText="Sel." Type="ColumnType.Number" TextAlign="TextAlign.Left" Width="30" AllowEditing="false" Freeze="FreezeDirection.Left" IsFrozen="_IsFrozen">
<Template>
@{
RowCountAI++;
<div>@RowCountAI</div>
}
</Template>
</GridColumn>
<GridColumn Field=@nameof(Anuncio.Id_Tbl_Entradas) HeaderText="Sel." Type="ColumnType.CheckBox" TextAlign="TextAlign.Left" Width="30" AllowEditing="false" IsPrimaryKey="true" Freeze="FreezeDirection.Left" IsFrozen="_IsFrozen">
</GridColumn>
<GridColumn Field=@nameof(Anuncio.Id_Tbl_Entradas) HeaderText="Sel." TextAlign="TextAlign.Left" Width="30" AllowEditing="false" IsPrimaryKey="true" Freeze="FreezeDirection.Left" IsFrozen="_IsFrozen">
<Template>
@{
<div class="bi-pencil" style="text-align: center;"></div>
}
</Template>
</GridColumn>
<GridColumn Field=@nameof(Anuncio.Id_Tbl_Entradas) HeaderText="Remove" TextAlign="TextAlign.Left" Width="30" AllowEditing="false" Freeze="FreezeDirection.Left" IsFrozen="_IsFrozen" AllowFiltering="false">
<Template>
@{
<div class="bi bi-trash3" style="text-align: center;"></div>
}
</Template>
</GridColumn>
<GridColumn Field=@nameof(Anuncio.NombrePlataforma) HeaderText="Platform" AllowEditing="false" Freeze="FreezeDirection.Left" IsFrozen="_IsFrozen" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.FechaEvento) HeaderText="Event Date" Format="dd/MM/yyyy HH:mm" Type="ColumnType.DateTime" TextAlign="TextAlign.Right" AllowEditing="false" Freeze="FreezeDirection.Left" IsFrozen="_IsFrozen" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.Event) HeaderText="Event" AllowEditing="false" Freeze="FreezeDirection.Left" IsFrozen="_IsFrozen" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.Venue) HeaderText="Venue" AllowEditing="false" Freeze="FreezeDirection.Left" IsFrozen="_IsFrozen" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.Pais) HeaderText="Country" AllowEditing="false" Freeze="FreezeDirection.Left" IsFrozen="_IsFrozen" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.Sector) HeaderText="Sector/Category" AllowEditing="false" Freeze="FreezeDirection.Left" IsFrozen="_IsFrozen" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.Reference) HeaderText="Reference" AllowEditing="false" Freeze="FreezeDirection.Left" IsFrozen="@_IsFrozen" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.FaceValue) HeaderText="Face Value" Type="ColumnType.Decimal" TextAlign="TextAlign.Right" AllowEditing="false" ></GridColumn>
<GridColumn Field=@nameof(Anuncio.Porcentaje) HeaderText="%" Type="ColumnType.Decimal" TextAlign="TextAlign.Right" AllowEditing="false" ></GridColumn>
<GridColumn Field=@nameof(Anuncio.PrecioLimite) HeaderText="Price Limit*" Type="ColumnType.Double" TextAlign="TextAlign.Right" EditType="EditType.NumericEdit" AllowEditing="true" ></GridColumn>
<GridColumn Field=@nameof(Anuncio.EnElLimite) HeaderText="Limit" Type="ColumnType.String" TextAlign="TextAlign.Right" AllowEditing="false" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
@* <GridColumn Field=@nameof(Anuncio.strTipoDeVenta) HeaderText="Competition*" Type="ColumnType.String" TextAlign="TextAlign.Right"></GridColumn> *@
<GridColumn Field=@nameof(Anuncio.strTipoDeVenta) HeaderText="Competition*" Type="ColumnType.String" EditType="EditType.DropDownEdit" TextAlign="TextAlign.Right" AllowEditing="true" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
@* <GridColumn Field=@nameof(Anuncio.strTipoDeVenta) HeaderText="Competition1*" Type="ColumnType.String" EditType="EditType.DropDownEdit" TextAlign="TextAlign.Right" AllowEditing="true">
<EditTemplate>
<SfDropDownList ID="Id_TiposVentas" Placeholder="Competition" TValue="long" TItem="TiposVentas" DataSource="@listadotiposventas">
<DropDownListEvents TValue="long"></DropDownListEvents>
<DropDownListFieldSettings Text="NombreTipoVenta" Value="Id_TiposVentas"></DropDownListFieldSettings>
</SfDropDownList>
</EditTemplate>
</GridColumn> *@
<GridColumn Field=@nameof(Anuncio.PrecioActual) HeaderText="Actual Price" Type="ColumnType.Decimal" TextAlign="TextAlign.Right" AllowEditing="false" ></GridColumn>
<GridColumn Field=@nameof(Anuncio.Proceeds) HeaderText="Proceeds" Type="ColumnType.Decimal" TextAlign="TextAlign.Right" AllowEditing="false" ></GridColumn>
<GridColumn Field=@nameof(Anuncio.NetPrice) HeaderText="Net Price" Type="ColumnType.Decimal" TextAlign="TextAlign.Right" AllowEditing="false" ></GridColumn>
<GridColumn Field=@nameof(Anuncio.Available) HeaderText="Available" Type="ColumnType.Integer" TextAlign="TextAlign.Right" AllowEditing="false" ></GridColumn>
<GridColumn Field=@nameof(Anuncio.Sold) HeaderText="Sold" Type="ColumnType.Integer" TextAlign="TextAlign.Right" AllowEditing="false" ></GridColumn>
<GridColumn Field=@nameof(Anuncio.NumeroAnunciosMasBaratos) HeaderText="Competition" Type="ColumnType.Integer" TextAlign="TextAlign.Right" AllowEditing="false" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.PrecioMasBajo) HeaderText="Lowest price" Type="ColumnType.Decimal" TextAlign="TextAlign.Right" AllowEditing="false" ></GridColumn>
<GridColumn Field=@nameof(Anuncio.FechaLecturaCompetencia) HeaderText="Last date limit price" Format="dd/MM/yyyy HH:mm" Type="ColumnType.DateTime" TextAlign="TextAlign.Left" AllowEditing="false" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
@* <GridColumn Field=@nameof(Anuncio.Turbo) HeaderText="Turbo*" Type="ColumnType.String" TextAlign="TextAlign.Right"></GridColumn> *@
<GridColumn Field=@nameof(Anuncio.Turbo) HeaderText="Turbo*" Type="ColumnType.String" TextAlign="TextAlign.Right" EditType="EditType.DropDownEdit" AllowEditing="true" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.Pending) HeaderText="Pending Execution" Type="ColumnType.String" TextAlign="TextAlign.Right" AllowEditing="false" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.Ejecutado) HeaderText="Executed Price Change" Type="ColumnType.String" TextAlign="TextAlign.Right" AllowEditing="false" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
<GridColumn Field=@nameof(Anuncio.Notes) HeaderText="Notes*" Type="ColumnType.String" TextAlign="TextAlign.Right" EditType="EditType.DefaultEdit" AllowEditing="true" FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn>
</GridColumns>
</SfGrid>
</div>
</div>
<BackOffice_V3.Client.Shared.Componentes.Ventana @ref="Ventana"></BackOffice_V3.Client.Shared.Componentes.Ventana>
@* <BackOffice_V3.Client.Shared.Componentes.VentanaDialog @ref="VentanaDialog" DialogOkCancel="DialogOkCancel" ></BackOffice_V3.Client.Shared.Componentes.VentanaDialog> *@
<style>
.fondoamarillo {
background-color: yellow;
}
.fuenterojo {
color: red !important;
}
</style>
@code {
BackOffice_V3.Shared.ListadoAnuncios Anuncio = new BackOffice_V3.Shared.ListadoAnuncios();
List<BackOffice_V3.Shared.ListadoAnuncios> listadoanuncios = new List<BackOffice_V3.Shared.ListadoAnuncios>();
List<BackOffice_V3.Shared.ListadoAnuncios> datos = new List<BackOffice_V3.Shared.ListadoAnuncios>();
BackOffice_V3.Client.Shared.Componentes.Ventana Ventana = new BackOffice_V3.Client.Shared.Componentes.Ventana();
//BackOffice_V3.Client.Shared.Componentes.VentanaDialog VentanaDialog = new BackOffice_V3.Client.Shared.Componentes.VentanaDialog();
//public int DialogResuelto { get; set; } = 0;
SfGrid<ListadoAnuncios> GridInstance { get; set; }
List<TiposVentas> listadotiposventas = new List<TiposVentas>();
[Parameter]
public EventCallback<long> EditarRegistro { get; set; } /* Refrescar grid */
public int RowCountAI = 0;
Based on your requirements, when using the
virtualization feature, it operates on an on-demand basis. Data is loaded as
needed, which is why you encountered issues with the previous suggested
approach. To address this, we recommend utilizing the GetRowIndexByPrimaryKeyAsync
public method. This method retrieves the row index based on the primary key
value and then displays it using a template feature within a GridColumn. Please
refer to the code snippet and sample below for your reference:
|
<div style="height: calc(100vh - 7rem);"> <SfGrid DataSource="@datos" @ref="@GridInstance" Height="100%" EnableStickyHeader="true" EnableVirtualization="true" AllowFiltering="true" AllowSorting="true" RowHeight="18" GridLines="Syncfusion.Blazor.Grids.GridLine.Both" <GridColumns>
<GridColumn Field=@nameof(Anuncio.Id_Tbl_Entradas) HeaderText="Sel." Type="Syncfusion.Blazor.Grids.ColumnType.Integer" TextAlign="Syncfusion.Blazor.Grids.TextAlign.Left" Width="30" AllowEditing="false" Freeze="Syncfusion.Blazor.Grids.FreezeDirection.Left" IsFrozen="true">
<Template>
@{
var data = context as Anuncio; var index = GridInstance.GetRowIndexByPrimaryKeyAsync(data.Id_Tbl_Entradas).Result; <span>Rowindex:@index</span> } </Template>
</GridColumn> </SfGrid> </div> @code {
SfGrid<Anuncio> GridInstance { get; set; } } |
Sample: https://blazorplayground.syncfusion.com/embed/VtBzDEjarHQYSLhn?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5
Reference: https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_GetRowIndexByPrimaryKeyAsync_System_Object_
Additionally ,We would like to inform you that it is generally recommended to use
either virtualization or paging when rendering a large number of records in
your application. We have observed that you have used both pagination
and virtualization in the Grid code you shared. It is not recommended to
use both paging and virtualization features in the same grid.
Paging works by displaying a specific set of data per page, while virtualization ensures that data is fetched only when needed, with a new block of data loaded each time you scroll. Both approaches can significantly enhance the responsiveness of your application. Therefore, please use only one of these features. Thank you for your understanding.
- 6 Replies
- 5 Participants
-
VI Vijay
- Jun 28, 2021 06:35 PM UTC
- Sep 9, 2024 12:29 PM UTC