- Notifications
You must be signed in to change notification settings - Fork 81
Added new kb article set-all-page-size-option-as-default #1812
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
Merged
ntacheva merged 6 commits into master from new-kb-set-all-page-size-option-as-default-77088c6f035547d699b97a8568b79b0b Jan 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
6 commits Select commit Hold shift + click to select a range
c766ad6 Added new kb article set-all-page-size-option-as-default
289bd5d Update knowledge-base/set-all-page-size-option-as-default.md
ntacheva aefcbc7 Update knowledge-base/set-all-page-size-option-as-default.md
ntacheva 63ad92f Update knowledge-base/set-all-page-size-option-as-default.md
ntacheva 72dbe5a Update knowledge-base/set-all-page-size-option-as-default.md
ntacheva 2c008d4 kb(grid): address feedback
ntacheva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| --- | ||
| title: Set "All" PageSize option as default | ||
| description: How to set the "All" option for the PageSize as default in Telerik Grid for Blazor. | ||
| type: how-to | ||
| page_title: Set "All" PageSize option as default | Telerik Grid for Blazor | ||
ntacheva marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| slug: set-all-page-size-option-as-default | ||
ntacheva marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| tags: | ||
ntacheva marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| - Telerik Grid | ||
| - Blazor | ||
| - Page Size | ||
| - All Option | ||
| - Default | ||
| ticketid: 1624891 | ||
| res_type: kb | ||
| --- | ||
| | ||
| ## Environment | ||
| | Property | Value | | ||
| | --- | --- | | ||
| | Product | Grid for Blazor | | ||
| | ||
| ## Description | ||
| | ||
| I want to set the default selected entry in the Pager of the Telerik Grid to be "All" items. However, the `PageSize` property only accepts a non-nullable `int`, so I cannot bind it to a nullable `int?` variable. Is there a way to initialize the `PageSize` with `null` to indicate that I want the "All" option as the default? | ||
| | ||
| ## Solution | ||
| | ||
| The `PageSize` property of the Grid accepts a non-nullable `int` by design. To set the "All" option as the default for the page size in the Telerik Grid, use a custom approach as follows: | ||
ntacheva marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| | ||
| 1. In the component's initialization method (`OnInitializedAsync`), load the data and set the `PageSize` property to the total count of the records. | ||
| 2. Add the "All" option (`null`) to the `PageSizes` collection. | ||
| 3. Bind the `PageSize` property to the `@bind-PageSize` attribute of the `TelerikGrid` component. | ||
| 4. Specify the `PageSizes` collection in the `GridPagerSettings` component to display the dropdown with the available page sizes. | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a step about setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is listed in the first step:
| ||
| | ||
| Here's an example implementation: | ||
| | ||
| ``` | ||
ntacheva marked this conversation as resolved. Show resolved Hide resolved | ||
| Page size: @PageSize | ||
| | ||
| <TelerikGrid Data="@GridData" | ||
| Pageable="true" | ||
| @bind-PageSize="@PageSize" | ||
| Height="500px"> | ||
| <GridSettings> | ||
| <GridPagerSettings InputType="PagerInputType.Buttons" | ||
| PageSizes="@PageSizes" | ||
| ButtonCount="5"> | ||
| </GridPagerSettings> | ||
| </GridSettings> | ||
| <GridColumns> | ||
| <GridColumn Field="@(nameof(Product.Name))" Title="Product Name" /> | ||
| <GridColumn Field="@(nameof(Product.Price))" /> | ||
| <GridColumn Field="@(nameof(Product.Released))" /> | ||
| <GridColumn Field="@(nameof(Product.Discontinued))" /> | ||
| </GridColumns> | ||
| </TelerikGrid> | ||
| | ||
| @code { | ||
| private List<Product> GridData { get; set; } = new List<Product>(); | ||
| | ||
| private int PageSize { get; set; } | ||
| | ||
| private List<int?> PageSizes { get; set; } = new List<int?> { null, 5, 10, 15 }; | ||
| | ||
| protected override async Task OnInitializedAsync() | ||
| { | ||
| await LoadData(); | ||
| | ||
| PageSize = GridData.Count(); | ||
| } | ||
| | ||
| private async Task LoadData() | ||
| { | ||
| GridData = Enumerable.Range(1, 30).Select(x => new Product | ||
| { | ||
| Id = x, | ||
| Name = "Product name " + x, | ||
| Price = (decimal)(x * 3.14), | ||
| Released = DateTime.Now.AddMonths(-x).Date, | ||
| Discontinued = x % 5 == 0 | ||
| }).ToList(); | ||
| } | ||
| | ||
| public class Product | ||
| { | ||
| public int Id { get; set; } | ||
| public string Name { get; set; } | ||
| public decimal Price { get; set; } | ||
| public DateTime Released { get; set; } | ||
| public bool Discontinued { get; set; } | ||
| } | ||
| } | ||
| ``` | ||
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.