-
Notifications
You must be signed in to change notification settings - Fork 0
25.1.3 feature #1
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1379249
README auto update [skip ci]
da977cd
Custom column chooser implemented. Moved data classes to separate files
Schullz faff81c
Merge branch '25.1.3-feature' of https://github.com/DevExpress-Exampl…
Schullz d572e28
Replaced inline styles with CSS classes for csp compliance
Schullz 8f2c66d
removed unnecessary variable in SelectedDataItemsChanged
Schullz 9109560
Moved styles to site.css for CSP complience
Schullz 55040f3
Applied Svetlana's recommendations after Demo
Schullz 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
| @@ -1,37 +1,119 @@ | ||
| @page "/" | ||
| @using CustomColumnChooser.Services | ||
| @inject WeatherForecastService ForecastService | ||
|
|
||
| <PageTitle>Welcome</PageTitle> | ||
|
|
||
| <DxButton Text="Show built-in column chooser" Click="() => MyGrid.ShowColumnChooser()"></DxButton> | ||
| <DxButton Text="Show custom column chooser" Click="@ShowCustomColumnChooser"></DxButton> | ||
|
|
||
| @if (forecasts == null) { | ||
| <p><em>Loading...</em></p> | ||
| } | ||
| else { | ||
| <DxGrid Data="@forecasts"> | ||
| <DxGrid @ref="@MyGrid" | ||
| Data="@forecasts"> | ||
| <Columns> | ||
| <DxGridDataColumn Caption="Date" FieldName="Date" /> | ||
| <DxGridSelectionColumn Caption="Selection Column" /> | ||
| <DxGridDataColumn Caption="Date" FieldName="Date" ShowInColumnChooser="false" /> | ||
| <DxGridDataColumn Caption="Temperature (C)" FieldName="TemperatureC" /> | ||
| <DxGridDataColumn Caption="Temperature (F)" FieldName="TemperatureF" /> | ||
| <DxGridDataColumn Caption="Summary" FieldName="Summary" /> | ||
| <DxGridDataColumn Caption="Description" FieldName="Summary" /> | ||
| </Columns> | ||
| </DxGrid> | ||
| } | ||
|
|
||
| <DxWindow @bind-Visible="@isCustomColumnChooserVisible" | ||
| HeaderText="Column Chooser" | ||
| Width="400px" | ||
| Height="auto" | ||
| ShowCloseButton="true"> | ||
| <BodyTemplate> | ||
| <div class="column-chooser-body"> | ||
| <DxListBox @ref="@columnListBox" | ||
| Data="@AllColumns" | ||
| ShowSearchBox="true" | ||
| SelectionMode="ListBoxSelectionMode.Multiple" | ||
| ShowCheckboxes="true" | ||
| ShowSelectAllCheckbox="true" | ||
| TextFieldName="Caption" | ||
| Values="VisibleColumns" | ||
| ValuesChanged="@((IEnumerable<IGridColumn> values) => SelectedDataItemsChanged(values))" | ||
| CssClass="column-listbox"> | ||
| </DxListBox> | ||
| <div class="column-chooser-buttons"> | ||
| <DxCheckBox Checked="ReverseOrder" CheckedChanged="@((bool value) => OnReverseOrder(value))"> | ||
| Reverse Order | ||
| </DxCheckBox> | ||
| </div> | ||
| </div> | ||
| </BodyTemplate> | ||
| </DxWindow> | ||
|
|
||
| <p>The Date column ShowInColumnChooser parameter is false - thus, it doesn't appear in the Column Chooser </p> | ||
| @code { | ||
| DxGrid MyGrid { get; set; } = default!; | ||
| DxListBox<IGridColumn, IGridColumn> columnListBox { get; set; } = default!; | ||
| private WeatherForecast[]? forecasts; | ||
| private bool isCustomColumnChooserVisible = false; | ||
| public IEnumerable<IGridColumn> AllColumns { get; set; } | ||
| public IEnumerable<IGridColumn> VisibleColumns { get; set; } | ||
| bool ReverseOrder { get; set; } = false; | ||
|
|
||
| #region Initialization | ||
| protected override async Task OnInitializedAsync() { | ||
| var startDate = DateOnly.FromDateTime(DateTime.Now); | ||
| var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; | ||
| forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast { | ||
| Date = startDate.AddDays(index), | ||
| TemperatureC = Random.Shared.Next(-20, 55), | ||
| Summary = summaries[Random.Shared.Next(summaries.Length)] | ||
| }).ToArray(); | ||
| } | ||
|
|
||
| private class WeatherForecast { | ||
| public DateOnly Date { get; set; } | ||
| public int TemperatureC { get; set; } | ||
| public string? Summary { get; set; } | ||
| public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
| forecasts = await ForecastService.GetForecastsAsync(); | ||
| } | ||
| protected override void OnAfterRender(bool firstRender) { | ||
| if (firstRender) { | ||
| InitializeColumnList(); | ||
| } | ||
| } | ||
| private void ShowCustomColumnChooser() { | ||
| isCustomColumnChooserVisible = true; | ||
| } | ||
| private void InitializeColumnList() { | ||
| AllColumns = MyGrid.GetColumns().Where(i => i.ShowInColumnChooser).OrderBy(i => i, ColumnsComparerImpl.Default).ToList(); | ||
| if (ReverseOrder) | ||
| AllColumns = AllColumns.Reverse(); | ||
| VisibleColumns = MyGrid.GetVisibleColumns(); | ||
| } | ||
| #endregion | ||
|
|
||
| #region Event Handling | ||
| void SelectedDataItemsChanged(IEnumerable<IGridColumn> values) | ||
| { | ||
| VisibleColumns = values; | ||
| UpdateColumnsVisibility(); | ||
| } | ||
| void UpdateColumnsVisibility() { | ||
| MyGrid.BeginUpdate(); | ||
| var columnCollection = MyGrid.GetColumns(); | ||
| foreach (var column in columnCollection) | ||
| if (column.ShowInColumnChooser) | ||
| column.Visible = VisibleColumns.Contains(column); | ||
| MyGrid.EndUpdate(); | ||
| } | ||
| private void OnReverseOrder(bool newValue) { | ||
| ReverseOrder = newValue; | ||
| AllColumns = AllColumns.Reverse(); | ||
| } | ||
| #endregion | ||
|
|
||
| class ColumnsComparerImpl : IComparer<IGridColumn> { | ||
| public static IComparer<IGridColumn> Default { get; } = new ColumnsComparerImpl(); | ||
| ColumnsComparerImpl() { } | ||
| int IComparer<IGridColumn>.Compare(IGridColumn x, IGridColumn y) { | ||
| if (x is IGridSelectionColumn) | ||
| return -1; | ||
| if (x is IGridCommandColumn && y is IGridDataColumn) | ||
| return -1; | ||
| if (x is IGridDataColumn xData && y is IGridDataColumn yData) { | ||
| var xName = !string.IsNullOrEmpty(xData.Caption) ? xData.Caption : xData.FieldName; | ||
| var yName = !string.IsNullOrEmpty(yData.Caption) ? yData.Caption : yData.FieldName; | ||
| return string.Compare(xName, yName); | ||
| } | ||
| return 0; | ||
| } | ||
| } | ||
| } | ||
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
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
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,12 @@ | ||
| using System; | ||
|
|
||
| namespace CustomColumnChooser.Services | ||
| { | ||
| public class WeatherForecast | ||
| { | ||
| public DateOnly Date { get; set; } | ||
| public int TemperatureC { get; set; } | ||
| public string? Summary { get; set; } | ||
| public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
| } | ||
| } |
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,28 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace CustomColumnChooser.Services | ||
| { | ||
| public class WeatherForecastService | ||
| { | ||
| private static readonly string[] Summaries = new[] | ||
| { | ||
| "Freezing", "Bracing", "Chilly", "Cool", "Mild", | ||
| "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
| }; | ||
|
|
||
| public Task<WeatherForecast[]> GetForecastsAsync(int days = 5) | ||
| { | ||
| var startDate = DateOnly.FromDateTime(DateTime.Now); | ||
| var forecasts = Enumerable.Range(1, days).Select(index => new WeatherForecast | ||
| { | ||
| Date = startDate.AddDays(index), | ||
| TemperatureC = Random.Shared.Next(-20, 55), | ||
| Summary = Summaries[Random.Shared.Next(Summaries.Length)] | ||
| }).ToArray(); | ||
|
|
||
| return Task.FromResult(forecasts); | ||
| } | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.