Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid: change total items from int to long #5902

Open
wants to merge 11 commits into
base: next-2.0
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

if ( !e.CancellationToken.IsCancellationRequested )
{
IEnumerable<Employee> response = ( await GetDataFromExternalSource( e.Page, e.PageSize ) );
IEnumerable<Employee> response = ( await GetDataFromExternalSource( (int)e.Page, e.PageSize ) );

if ( !e.CancellationToken.IsCancellationRequested )
{
Expand Down
62 changes: 62 additions & 0 deletions Demos/Blazorise.Demo/Pages/Tests/DataGrid/DataGridLargePage.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@page "/tests/datagridlarge"

<h3>DataGrid on datasets larger than int.MaxValue</h3>

<DataGrid TItem="LargeModelItem"
Data="items"
TotalItems="totalCount"
ReadData="OnDataRead"
ShowPager
>
<DataGridColumn Field="@nameof( LargeModelItem.Id )" Caption="id" />
<DataGridColumn Field="@nameof( LargeModelItem.Name )" Caption="Name" Editable/>
</DataGrid>



@code {
class LargeModelItem
{
public long Id { get; set; }
public string Name { get; set; } = "";
}


long totalCount = 10_000_000_000_000;//

IEnumerable<LargeModelItem> items = Enumerable.Empty<LargeModelItem>();

private void OnDataRead(DataGridReadDataEventArgs<LargeModelItem> e)
{

// if (e.ReadDataMode == DataGridReadDataMode.Virtualize)
// {
//
// items = Enumerable.Range(e.VirtualizeOffset, e.VirtualizeCount).Select(i => new LargeModelItem
// {
// Id = i,
// Name = $"Item id { i} "
// });
// }

if (e.ReadDataMode == DataGridReadDataMode.Paging)
{
items = LongRange((e.Page - 1) * e.PageSize, e.PageSize)
.Select(i => new LargeModelItem
{
Id = i,
Name = $"Item id {i}"
});
}

}


public static IEnumerable<long> LongRange(long start, long count)
{
for (long i = 0; i < count; i++)
{
yield return start + i;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class DataGridPage
private TableResponsiveMode responsiveMode = TableResponsiveMode.Default;

private DataGrid<Employee> dataGrid;
public int currentPage { get; set; } = 1;
public long currentPage { get; set; } = 1;
public int currentPageSize { get; set; } = 5;

private bool editable = true;
Expand Down
2 changes: 1 addition & 1 deletion Demos/Blazorise.Demo/Pages/Tests/DataGrid/PagerPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<ItemsPerPageTemplate></ItemsPerPageTemplate>
<PageSelectorTemplate>
<Select TextColor="TextColor.Success" @bind-Value="@context.Page" Size="Size.Small">
@for ( int i = context.FirstVisiblePage; i <= context.LastVisiblePage; ++i )
@for ( long i = context.FirstVisiblePage; i <= context.LastVisiblePage; ++i )
{
var pageNumber = i;
<SelectItem Value="@pageNumber">@pageNumber</SelectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
<Blazorise.Link To="https://github.com/dotnet/aspnetcore/issues/28280">TaskCanceledException when scrolling Virtualized component #28280</Blazorise.Link>
</AlertDescription>
</Alert>

<Alert Margin="Margin.Is4.FromTop" Color="Color.Info" Visible>
<AlertDescription>
Virtualization does not support large datasets (approximately 1 million or more items, depending on the height of the items). This is a known browser technical limitation.
<Blazorise.Link To="https://github.com/dotnet/aspnetcore/issues/26354">See more</Blazorise.Link>
For scenarios involving very large datasets, we strongly recommend using a pagination approach instead.
</AlertDescription>
</Alert>
</DocsPageSectionHeader>
<DocsPageSectionContent FullWidth>
<DataGridVirtualizeExample />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
if ( e.ReadDataMode is DataGridReadDataMode.Virtualize )
response = employeeList.Skip( e.VirtualizeOffset ).Take( e.VirtualizeCount ).ToList();
else if ( e.ReadDataMode is DataGridReadDataMode.Paging )
response = employeeList.Skip( ( e.Page - 1 ) * e.PageSize ).Take( e.PageSize ).ToList();
response = employeeList.Skip( (int)( e.Page - 1 ) * e.PageSize ).Take( e.PageSize ).ToList();// Converting to `int` is necessary for the `Skip()` method. However, it will still break on datasets larger than `int.MaxValue` items. Be mindful of the size of your data.
else
throw new Exception( "Unhandled ReadDataMode" );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
if ( e.ReadDataMode is DataGridReadDataMode.Virtualize )
response = ( await EmployeeData.GetDataAsync() ).Skip( e.VirtualizeOffset ).Take( e.VirtualizeCount ).ToList();
else if ( e.ReadDataMode is DataGridReadDataMode.Paging )
response = ( await EmployeeData.GetDataAsync() ).Skip( ( e.Page - 1 ) * e.PageSize ).Take( e.PageSize ).ToList();
response = ( await EmployeeData.GetDataAsync() ).Skip((int)( e.Page - 1 ) * e.PageSize )// Converting to `int` is necessary for the `Skip()` method. However, it will still break on datasets larger than `int.MaxValue` items. Be mindful of the size of your data.
.Take( e.PageSize ).ToList();
else
throw new Exception( "Unhandled ReadDataMode" );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
if (e.ReadDataMode is DataGridReadDataMode.Virtualize)
response = query.ApplyDataGridPaging(e.VirtualizeOffset + 1, e.VirtualizeCount).ToList();
else if (e.ReadDataMode is DataGridReadDataMode.Paging)
response = query.ApplyDataGridPaging(e.Page, e.PageSize).ToList();
response = query.ApplyDataGridPaging((int)e.Page, e.PageSize).ToList();
else
throw new Exception("Unhandled ReadDataMode");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<ItemsPerPageTemplate></ItemsPerPageTemplate>
<PageSelectorTemplate>
<Select TextColor="TextColor.Success" @bind-Value="@context.Page" Size="Size.Small">
@for ( int i = context.FirstVisiblePage; i <= context.LastVisiblePage; ++i )
@for ( long i = context.FirstVisiblePage; i <= context.LastVisiblePage; ++i )
{
var pageNumber = i;
<SelectItem Value="@pageNumber">@pageNumber</SelectItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<Strong>DataGridSelectColumn</Strong>: Multiple support
</Paragraph>
</UnorderedListItem>

<UnorderedListItem>
<Paragraph>
<Strong>DataGrid</Strong>: Support for datasets larger than <Code>int.MaxValue</Code> items
</Paragraph>
</UnorderedListItem>
</UnorderedList>

<Paragraph>
Expand Down Expand Up @@ -107,6 +113,33 @@
</UnorderedListItem>
</UnorderedList>
</OrderedListItem>

<OrderedListItem>
<Paragraph>
DataGrid TotalItems is now long instead of int. Here is the list of all properties that have been changed to <Code>long</Code>
</Paragraph>
<UnorderedList>
<UnorderedListItem>
<Strong>DataGrid:</Strong> <Code>TotalItems</Code>, <Code>CurrentPage</Code> (renamed to <Code>Page</Code> in 2.0), <Code>SelectedRowIndex</Code>
</UnorderedListItem>

<UnorderedListItem>
<Strong>PaginationContext:</Strong> <Code>CurrentPage</Code>, <Code>LastPage</Code>, <Code>FirstVisiblePage</Code>, <Code>LastVisiblePage</Code>, <Code>TotalItems</Code>
</UnorderedListItem>

<UnorderedListItem>
<Strong>PageButtonContext:</Strong> <Code>PageNumber</Code>
</UnorderedListItem>

<UnorderedListItem>
<Strong>DataGridFilteredDataEventArgs:</Strong> <Code>TotalItems</Code>
</UnorderedListItem>

<UnorderedListItem>
<Strong>DataGridReadDataEventArguments:</Strong> <Code>Page</Code>
</UnorderedListItem>
</UnorderedList>
</OrderedListItem>
</OrderedList>
</Paragraph>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PageButtonContext
/// </summary>
/// <param name="pageNumber">Button page number .</param>
/// <param name="active">Indicates if page is active.</param>
public PageButtonContext( int pageNumber, bool active )
public PageButtonContext( long pageNumber, bool active )
{
PageNumber = pageNumber;
Active = active;
Expand All @@ -23,13 +23,13 @@ public PageButtonContext( int pageNumber, bool active )
/// <summary>
/// Gets the page number.
/// </summary>
public int PageNumber { get; private set; }
public long PageNumber { get; private set; }

/// <summary>
/// Gets the page number.
/// </summary>
[Obsolete( "PageNumer is deprecated and will be removed in future versions, please use PageNumber instead.", true )]
public int PageNumer { get { return PageNumber; } set { PageNumber = value; } }
public long PageNumer { get { return PageNumber; } set { PageNumber = value; } }

/// <summary>
/// Get the flag that indicates if the page is active.
Expand Down
28 changes: 14 additions & 14 deletions Source/Extensions/Blazorise.DataGrid/Contexts/PaginationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ public class PaginationContext<TItem>

private event PageChangedEventHandler PageChanged;

public delegate void PageChangedEventHandler( int value );
public delegate void PageChangedEventHandler( long value );

private event PageSizeChangedEventHandler PageSizeChanged;

public delegate void PageSizeChangedEventHandler( int value );

private event TotalItemsChangedEventHandler TotalItemsChanged;

public delegate void TotalItemsChangedEventHandler( int value );
public delegate void TotalItemsChangedEventHandler( long value );

private int firstVisiblePage;
private long firstVisiblePage;

private int lastVisiblePage;
private long lastVisiblePage;

private int page = 1;
private long page = 1;

private int pageSize = 10;

private int? totalItems;
private long? totalItems;

private DataGrid<TItem> parentDataGrid;

Expand All @@ -58,7 +58,7 @@ public void UnsubscribeOnPageChanged( PageChangedEventHandler listener )
PageChanged -= listener;
}

public void TriggerPageChange( int value )
public void TriggerPageChange( long value )
{
PageChanged?.Invoke( value );
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public void UnsubscribeOnTotalItemsChanged( TotalItemsChangedEventHandler listen
TotalItemsChanged -= listener;
}

public void TriggerTotalItemsChange( int value )
public void TriggerTotalItemsChange( long value )
{
TotalItemsChanged?.Invoke( value );
}
Expand Down Expand Up @@ -132,7 +132,7 @@ private void CalculateFirstAndLastVisiblePage()
/// <summary>
/// Gets or sets the current page
/// </summary>
public int Page
public long Page
{
get => page;
set
Expand All @@ -148,11 +148,11 @@ public int Page
/// <summary>
/// Gets the last page number.
/// </summary>
public int LastPage
public long LastPage
{
get
{
var lastPage = Math.Max( (int)Math.Ceiling( ( TotalItems ?? 0 ) / (double)pageSize ), 1 );
long lastPage = Math.Max( (long)Math.Ceiling( ( TotalItems ?? 0 ) / (double)pageSize ), 1 );

if ( Page > lastPage )
Page = lastPage;
Expand All @@ -164,7 +164,7 @@ public int LastPage
/// <summary>
/// Gets the number of the first page that can be clicked in a large dataset.
/// </summary>
public int FirstVisiblePage
public long FirstVisiblePage
{
get
{
Expand All @@ -177,7 +177,7 @@ public int FirstVisiblePage
/// <summary>
/// Gets the number of the last page that can be clicked in a large dataset.
/// </summary>
public int LastVisiblePage
public long LastVisiblePage
{
get
{
Expand Down Expand Up @@ -215,7 +215,7 @@ public int PageSize
/// <remarks>
/// This field must be set only when <see cref="DataGrid{TItem}.ReadData"/> is used to load the data.
/// </remarks>
public int? TotalItems
public long? TotalItems
{
// If we're using ReadData than TotalItems must be set so we can know how many items are available
get => ( ( parentDataGrid.ManualReadMode || parentDataGrid.VirtualizeManualReadMode ) ? totalItems : parentDataGrid.FilteredData?.Count() ) ?? 0;
Expand Down
Loading
Loading