Skip to content

Commit

Permalink
New location for ChangePageSize (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavnavar committed Nov 21, 2021
1 parent dcef6dc commit ce6feec
Show file tree
Hide file tree
Showing 63 changed files with 498 additions and 193 deletions.
10 changes: 0 additions & 10 deletions GridBlazor/Pages/GridComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,6 @@
}
</div>
}
@if (Grid.EnablePaging && Grid.Pager.ChangePageSize)
{
<div class="grid-change-page-size form-group" data-change-page-size-url="@_changePageSizeUrl">
<label class="control-label"><b>@Strings.Show</b></label>
<div>
<input @ref="PageSizeInput" class="form-control grid-change-page-size-input" @bind="_pageSize" @onkeyup="InputPageSizeKeyup" @onblur="InputPageSizeBlur" @onclick:stopPropagation />
</div>
<label class="control-label"><b>@Strings.Items</b></label>
</div>
}
</div>
@if (Grid.SearchingEnabled)
{
Expand Down
20 changes: 10 additions & 10 deletions GridBlazor/Pages/GridComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public partial class GridComponent<T>
internal bool RequiredTotalsColumn = false;
private string gridTableHead = Guid.NewGuid().ToString("N");
private string gridTableBody = Guid.NewGuid().ToString("N");
protected string _changePageSizeUrl;
protected int _pageSize;
internal string ChangePageSizeUrl;
internal int PageSize;
internal bool[] IsSubGridVisible;
internal bool[] InitSubGrid;
protected IQueryDictionary<Type> _filterComponents;
Expand Down Expand Up @@ -103,7 +103,7 @@ public partial class GridComponent<T>

public QueryDictionary<GridHeaderComponent<T>> HeaderComponents { get; private set; }

public ElementReference PageSizeInput { get; private set; }
public ElementReference PageSizeInput { get; internal set; }

public GridSearchComponent<T> SearchComponent { get; private set; }

Expand Down Expand Up @@ -253,8 +253,8 @@ protected override void OnParametersSet()

var queryBuilder = new CustomQueryStringBuilder(Grid.Settings.SearchSettings.Query);
var exceptQueryParameters = new List<string> { GridPager.DefaultPageSizeQueryParameter };
_changePageSizeUrl = queryBuilder.GetQueryStringExcept(exceptQueryParameters);
_pageSize = Grid.Pager.ChangePageSize && Grid.Pager.QueryPageSize > 0 ? Grid.Pager.QueryPageSize : Grid.Pager.PageSize;
ChangePageSizeUrl = queryBuilder.GetQueryStringExcept(exceptQueryParameters);
PageSize = Grid.Pager.ChangePageSize && Grid.Pager.QueryPageSize > 0 ? Grid.Pager.QueryPageSize : Grid.Pager.PageSize;

_shouldRender = true;
}
Expand Down Expand Up @@ -1445,16 +1445,16 @@ public async Task InputPageSizeKeyup(KeyboardEventArgs e)

public async Task InputPageSizeBlur()
{
if (_pageSize > 0)
if (PageSize > 0)
{
Grid.Pager.PageSize = _pageSize;
Grid.AddQueryParameter(GridPager.DefaultPageSizeQueryParameter, _pageSize.ToString());
Grid.Pager.PageSize = PageSize;
Grid.AddQueryParameter(GridPager.DefaultPageSizeQueryParameter, PageSize.ToString());
await UpdateGrid();
await OnPagerChanged();
}
else
{
_pageSize = Grid.Pager.PageSize;
PageSize = Grid.Pager.PageSize;
_shouldRender = true;
StateHasChanged();
}
Expand All @@ -1464,7 +1464,7 @@ public async Task ChangePageSize(int pageSize)
{
if (pageSize > 0)
{
_pageSize = pageSize;
PageSize = pageSize;
Grid.Pager.PageSize = pageSize;
Grid.AddQueryParameter(GridPager.DefaultPageSizeQueryParameter, pageSize.ToString());
await UpdateGrid();
Expand Down
111 changes: 66 additions & 45 deletions GridBlazor/Pages/GridPagerComponent.razor
Original file line number Diff line number Diff line change
@@ -1,61 +1,82 @@
@typeparam T
@using GridBlazor.Resources
@typeparam T

@if (GridPager != null && GridPager.PageCount > 1)
{
<nav class="grid-pager">
<ul class="pagination">
@if (GridPager.CurrentPage > 1)
{
<li class="page-item">
<button type="button" class="page-link" @onclick="() => PagerButtonClicked(GridPager.CurrentPage - 1)">«</button>
</li>
}
@if (GridPager.StartDisplayedPage > 1)
{
<li class="page-item">
<button type="button" class="page-link" @onclick="() => PagerButtonClicked(1)">1</button>
</li>
@if (GridPager.StartDisplayedPage > 2)
<div class="grid-pager-sizer">
@if (GridPager != null && GridPager.PageCount > 1)
{
<nav class="grid-pager">
<ul class="pagination">
@if (GridPager.CurrentPage > 1)
{
<li class="page-item">
<button type="button" class="page-link" @onclick="() => PagerButtonClicked(GridPager.StartDisplayedPage - 1)">...</button>
<button type="button" class="page-link" @onclick="() => PagerButtonClicked(GridPager.CurrentPage - 1)">«</button>
</li>
}
}
@for (int i = GridPager.StartDisplayedPage; i <= GridPager.EndDisplayedPage; i++)
{
if (i == GridPager.CurrentPage)
@if (GridPager.StartDisplayedPage > 1)
{
<li class="page-item active">
<button type="button" class="page-link">@i <span class="sr-only">(current)</span></button>
<li class="page-item">
<button type="button" class="page-link" @onclick="() => PagerButtonClicked(1)">1</button>
</li>
@if (GridPager.StartDisplayedPage > 2)
{
<li class="page-item">
<button type="button" class="page-link" @onclick="() => PagerButtonClicked(GridPager.StartDisplayedPage - 1)">...</button>
</li>
}
}
@for (int i = GridPager.StartDisplayedPage; i <= GridPager.EndDisplayedPage; i++)
{
if (i == GridPager.CurrentPage)
{
<li class="page-item active">
<button type="button" class="page-link">@i <span class="sr-only">(current)</span></button>
</li>
}
else
{
int j = i;
<li class="page-item">
<button type="button" class="page-link" @onclick="async () => await PagerButtonClicked(j)">@j</button>
</li>
}
}
else
@if (GridPager.EndDisplayedPage < GridPager.PageCount)
{
int j = i;
if (GridPager.EndDisplayedPage < GridPager.PageCount - 1)
{
<li class="page-item">
<button type="button" class="page-link" @onclick="async () => await PagerButtonClicked(GridPager.EndDisplayedPage + 1)">...</button>
</li>
}
<li class="page-item">
<button type="button" class="page-link" @onclick="async () => await PagerButtonClicked(j)">@j</button>
<button type="button" class="page-link" @onclick="async () => await PagerButtonClicked(GridPager.PageCount)">@GridPager.PageCount</button>
</li>
}
}
@if (GridPager.EndDisplayedPage < GridPager.PageCount)
{
if (GridPager.EndDisplayedPage < GridPager.PageCount - 1)
@if (GridPager.CurrentPage < GridPager.PageCount)
{
<li class="page-item">
<button type="button" class="page-link" @onclick="async () => await PagerButtonClicked(GridPager.EndDisplayedPage + 1)">...</button>
<button type="button" class="page-link" @onclick="async () => await PagerButtonClicked(GridPager.CurrentPage + 1)">»</button>
</li>
}
<li class="page-item">
<button type="button" class="page-link" @onclick="async () => await PagerButtonClicked(GridPager.PageCount)">@GridPager.PageCount</button>
</li>
}
@if (GridPager.CurrentPage < GridPager.PageCount)
{
<li class="page-item">
<button type="button" class="page-link" @onclick="async () => await PagerButtonClicked(GridPager.CurrentPage + 1)">»</button>
</li>
}
</ul>
</nav>
}
</ul>
</nav>

<div class="grid-goto-page form-group">
<label class="control-label"><b>@Strings.Goto</b></label>
<div>
<input class="form-control grid-goto-page-input" @bind="_currentPage" @onkeyup="GoToKeyup" @onblur="GoToBlur" @onclick:stopPropagation />
</div>
</div>
}

@if (GridComponent.Grid.EnablePaging && GridComponent.Grid.Pager.ChangePageSize)
{
<div class="grid-change-page-size form-group" data-change-page-size-url="@GridComponent.ChangePageSizeUrl">
<label class="control-label"><b>@Strings.Show</b></label>
<div>
<input @ref="GridComponent.PageSizeInput" class="form-control grid-change-page-size-input" @bind="GridComponent.PageSize" @onkeyup="GridComponent.InputPageSizeKeyup" @onblur="GridComponent.InputPageSizeBlur" @onclick:stopPropagation />
</div>
<label class="control-label"><b>@Strings.Items</b></label>
</div>
}
</div>
21 changes: 21 additions & 0 deletions GridBlazor/Pages/GridPagerComponent.razor.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
using GridBlazor.Pagination;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using System.Threading.Tasks;

namespace GridBlazor.Pages
{
public partial class GridPagerComponent<T>
{
private int _currentPage;

[CascadingParameter (Name = "GridComponent")]
private GridComponent<T> GridComponent { get; set; }

[Parameter]
public GridPager GridPager { get; set; }

protected override void OnParametersSet()
{
_currentPage = GridPager.CurrentPage;
}

protected async Task PagerButtonClicked(int page)
{
await GridComponent.GoTo(page);
}

public async Task GoToKeyup(KeyboardEventArgs e)
{
if (e.Key == "Enter")
{
await GoToBlur();
}
}

public async Task GoToBlur()
{
await GridComponent.GoTo(_currentPage);
}
}
}
13 changes: 11 additions & 2 deletions GridBlazor/Resources/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.bg.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>Кода и кода за потвърждение трябва да са равни за да изтриете успешно</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Отидете на</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.ca-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>El codi i el codi de confirmació han de ser els mateixos per eliminar aquest element</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Anar a</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.cs.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>Kód a potvrzovací kód se musí rovnat odstranění této položky.</value>
</data>
<data name="String1" xml:space="preserve">
<value>Jít do</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>Code und Bestätigungscode müssen gleich sein, um dieses Element zu löschen</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Gehe zu</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>El código y el código de confirmación deben ser iguales para eliminar este elemento</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Ir a</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.eu-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>Kodeak eta berrespen-kodeak berdinak izan behar dute elementu hau kentzeko</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Joan</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.fa-IR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>کد و کد تایید باید برابر با حذف این مورد باشد</value>
</data>
<data name="Goto" xml:space="preserve">
<value>برو به</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>Le code et le code de confirmation doivent être égaux pour supprimer cet élément</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Aller à</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.gl-ES.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>O código e o código de confirmación deben ser os mesmos para eliminar este elemento</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Ir a</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.hr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>Šifra i kôd potvrde moraju biti jednaki za brisanje ove stavke</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Menj</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.it.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>Il codice e il codice di conferma devono essere uguali per eliminare questo elemento</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Vai a</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.nb-NO.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>Kode og bekreftelseskode må være lik for å slette dette elementet</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Gå til</value>
</data>
</root>
3 changes: 3 additions & 0 deletions GridBlazor/Resources/Strings.nl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@
<data name="DeleteConfirmCodeError" xml:space="preserve">
<value>Code en bevestigingscode moeten gelijk zijn om dit item te verwijderen</value>
</data>
<data name="Goto" xml:space="preserve">
<value>Ga naar</value>
</data>
</root>
Loading

0 comments on commit ce6feec

Please sign in to comment.