-
-
Notifications
You must be signed in to change notification settings - Fork 533
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DataGrid: Auto Generate Columns (#5232)
* DataGrid | Make it so the DataGrid is able to programatically add columns correctly * DataGrid | AutoGenerateColumns based on model properties * try crlf * AutoGenerateColumns | NullCheck Columns | Generate even if Command Or MultiSelect columns are defined. * DataGridColumn | Fix defaults initialization | It needs to be OnInitialized after parameters are set * ResolveCaption | PascalCaseToFriendlyName * PascalCaseToFriendlyName_Returns_FriendlyFormat | Add null case * Generate Select for enum | Editable If setter available * Add demo page for Auto Generate Columns * Dashboard revert to original * Docs : Add example page
- Loading branch information
1 parent
7b705df
commit 5c58cf8
Showing
16 changed files
with
449 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
55 changes: 55 additions & 0 deletions
55
Demos/Blazorise.Demo/Pages/Tests/DataGrid/AutoGenerateColumnsPage.razor
This file contains 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,55 @@ | ||
@page "/tests/datagrid/auto-generate-columns" | ||
@using System.ComponentModel.DataAnnotations | ||
<Row> | ||
<Column> | ||
<Card Margin="Margin.Is4.OnY"> | ||
<CardHeader> | ||
<CardTitle>Datagrid: Auto Generate Columns</CardTitle> | ||
</CardHeader> | ||
<CardBody> | ||
<DataGrid TItem="Example" | ||
Data="data" | ||
Responsive | ||
ShowPager | ||
ShowPageSizes Editable> | ||
<DataGridCommandColumn TItem="Example" /> | ||
</DataGrid> | ||
</CardBody> | ||
</Card> | ||
</Column> | ||
</Row> | ||
|
||
@code { | ||
|
||
public class Example | ||
{ | ||
[DisplayAttribute(Name = "Name")] | ||
public string FirstName { get; set; } | ||
|
||
public string LastName { get; set; } | ||
|
||
|
||
public int Age { get; set; } | ||
|
||
public decimal Balance { get; set; } | ||
|
||
public Status Status { get; set; } | ||
} | ||
|
||
public enum Status | ||
{ | ||
Active, | ||
Inactive | ||
} | ||
|
||
private IEnumerable<Example> data = new List<Example>() | ||
{ | ||
new(){ FirstName = "John", LastName = "Doe", Age = 30, Balance = 1000, Status = Status.Active }, | ||
new(){ FirstName = "Jane", LastName = "Doe", Age = 28, Balance = 2000, Status = Status.Active }, | ||
new(){ FirstName = "Joe", LastName = "Doe", Age = 26, Balance = 3000, Status = Status.Inactive }, | ||
new(){ FirstName = "Jill", LastName = "Doe", Age = 24, Balance = 4000, Status = Status.Inactive }, | ||
new(){ FirstName = "Jack", LastName = "Doe", Age = 22, Balance = 5000, Status = Status.Active }, | ||
new(){ FirstName = "Jen", LastName = "Doe", Age = 20, Balance = 6000, Status = Status.Active }, | ||
}; | ||
|
||
} |
This file contains 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 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
49 changes: 49 additions & 0 deletions
49
...rise.Docs/Pages/Docs/Extensions/DataGrid/Code/DataGridAutoGenerateColumnsExampleCode.html
This file contains 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,49 @@ | ||
<div class="blazorise-codeblock"> | ||
<div class="html"><pre> | ||
<span class="atSign">@</span>using System.ComponentModel.DataAnnotations | ||
|
||
<span class="htmlTagDelimiter"><</span><span class="htmlElementName">DataGrid</span> <span class="htmlAttributeName">TItem</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">Example</span><span class="quot">"</span> | ||
<span class="htmlAttributeName">Data</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">data</span><span class="quot">"</span> | ||
<span class="htmlAttributeName">Responsive</span> | ||
<span class="htmlAttributeName">ShowPager</span> | ||
<span class="htmlAttributeName">ShowPageSizes</span> <span class="htmlAttributeName">Editable</span><span class="htmlTagDelimiter">></span> | ||
<span class="htmlTagDelimiter"><</span><span class="htmlElementName">DataGridCommandColumn</span> <span class="htmlAttributeName">TItem</span><span class="htmlOperator">=</span><span class="quot">"</span><span class="htmlAttributeValue">Example</span><span class="quot">"</span> <span class="htmlTagDelimiter">/></span> | ||
<span class="htmlTagDelimiter"></</span><span class="htmlElementName">DataGrid</span><span class="htmlTagDelimiter">></span> | ||
</pre></div> | ||
<div class="csharp"><pre> | ||
<span class="atSign">@</span>code { | ||
|
||
<span class="keyword">public</span> <span class="keyword">class</span> Example | ||
{ | ||
[Display( Name = <span class="string">"Name"</span> )] | ||
<span class="keyword">public</span> <span class="keyword">string</span> FirstName { <span class="keyword">get</span>; <span class="keyword">set</span>; } | ||
|
||
<span class="keyword">public</span> <span class="keyword">string</span> LastName { <span class="keyword">get</span>; <span class="keyword">set</span>; } | ||
|
||
|
||
<span class="keyword">public</span> <span class="keyword">int</span> Age { <span class="keyword">get</span>; <span class="keyword">set</span>; } | ||
|
||
<span class="keyword">public</span> <span class="keyword">decimal</span> Balance { <span class="keyword">get</span>; <span class="keyword">set</span>; } | ||
|
||
<span class="keyword">public</span> Status Status { <span class="keyword">get</span>; <span class="keyword">set</span>; } | ||
} | ||
|
||
<span class="keyword">public</span> <span class="keyword">enum</span> Status | ||
{ | ||
Active, | ||
Inactive | ||
} | ||
|
||
<span class="keyword">private</span> IEnumerable<Example> data = <span class="keyword">new</span> List<Example>() | ||
{ | ||
<span class="keyword">new</span>(){ FirstName = <span class="string">"John"</span>, LastName = <span class="string">"Doe"</span>, Age = <span class="number">30</span>, Balance = <span class="number">1000</span>, Status = Status.Active }, | ||
<span class="keyword">new</span>(){ FirstName = <span class="string">"Jane"</span>, LastName = <span class="string">"Doe"</span>, Age = <span class="number">28</span>, Balance = <span class="number">2000</span>, Status = Status.Active }, | ||
<span class="keyword">new</span>(){ FirstName = <span class="string">"Joe"</span>, LastName = <span class="string">"Doe"</span>, Age = <span class="number">26</span>, Balance = <span class="number">3000</span>, Status = Status.Inactive }, | ||
<span class="keyword">new</span>(){ FirstName = <span class="string">"Jill"</span>, LastName = <span class="string">"Doe"</span>, Age = <span class="number">24</span>, Balance = <span class="number">4000</span>, Status = Status.Inactive }, | ||
<span class="keyword">new</span>(){ FirstName = <span class="string">"Jack"</span>, LastName = <span class="string">"Doe"</span>, Age = <span class="number">22</span>, Balance = <span class="number">5000</span>, Status = Status.Active }, | ||
<span class="keyword">new</span>(){ FirstName = <span class="string">"Jen"</span>, LastName = <span class="string">"Doe"</span>, Age = <span class="number">20</span>, Balance = <span class="number">6000</span>, Status = Status.Active }, | ||
}; | ||
|
||
} | ||
</pre></div> | ||
</div> |
45 changes: 45 additions & 0 deletions
45
...ise.Docs/Pages/Docs/Extensions/DataGrid/Examples/DataGridAutoGenerateColumnsExample.razor
This file contains 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,45 @@ | ||
@namespace Blazorise.Docs.Docs.Examples | ||
@using System.ComponentModel.DataAnnotations | ||
|
||
<DataGrid TItem="Example" | ||
Data="data" | ||
Responsive | ||
ShowPager | ||
ShowPageSizes Editable> | ||
<DataGridCommandColumn TItem="Example" /> | ||
</DataGrid> | ||
|
||
@code { | ||
|
||
public class Example | ||
{ | ||
[Display( Name = "Name" )] | ||
public string FirstName { get; set; } | ||
|
||
public string LastName { get; set; } | ||
|
||
|
||
public int Age { get; set; } | ||
|
||
public decimal Balance { get; set; } | ||
|
||
public Status Status { get; set; } | ||
} | ||
|
||
public enum Status | ||
{ | ||
Active, | ||
Inactive | ||
} | ||
|
||
private IEnumerable<Example> data = new List<Example>() | ||
{ | ||
new(){ FirstName = "John", LastName = "Doe", Age = 30, Balance = 1000, Status = Status.Active }, | ||
new(){ FirstName = "Jane", LastName = "Doe", Age = 28, Balance = 2000, Status = Status.Active }, | ||
new(){ FirstName = "Joe", LastName = "Doe", Age = 26, Balance = 3000, Status = Status.Inactive }, | ||
new(){ FirstName = "Jill", LastName = "Doe", Age = 24, Balance = 4000, Status = Status.Inactive }, | ||
new(){ FirstName = "Jack", LastName = "Doe", Age = 22, Balance = 5000, Status = Status.Active }, | ||
new(){ FirstName = "Jen", LastName = "Doe", Age = 20, Balance = 6000, Status = Status.Active }, | ||
}; | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...tion/Blazorise.Docs/Pages/Docs/Extensions/DataGrid/Features/AutoGenerateColumnsPage.razor
This file contains 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,34 @@ | ||
@page "/docs/extensions/datagrid/features/auto-generate-columns" | ||
|
||
<Seo Canonical="/docs/extensions/datagrid/features/auto-generate-columns" Title="Blazorise DataGrid Auto Generate Columns" Description="Learn Blazorise by the example. The DataGrid can automatically generate columns based on the TItem type." /> | ||
|
||
<DocsPageTitle Path="Extensions/DataGrid/Features/Auto Generate Columns"> | ||
Blazorise DataGrid: Auto Generate Columns | ||
</DocsPageTitle> | ||
|
||
<DocsPageLead> | ||
The DataGrid can automatically generate columns based on the TItem type. | ||
</DocsPageLead> | ||
|
||
<DocsPageSubtitle> | ||
Overview | ||
</DocsPageSubtitle> | ||
|
||
<DocsPageParagraph> | ||
If no columns are defined, the DataGrid will automatically generate columns based on the TItem type. | ||
</DocsPageParagraph> | ||
|
||
<DocsPageSubtitle> | ||
Example | ||
</DocsPageSubtitle> | ||
|
||
<DocsPageSection> | ||
<DocsPageSectionContent FullWidth Outlined> | ||
<DataGridAutoGenerateColumnsExample /> | ||
</DocsPageSectionContent> | ||
<DocsPageSectionSource Code="DataGridAutoGenerateColumnsExample" /> | ||
</DocsPageSection> | ||
|
||
<DocsPageApi> | ||
<DocsPageApiItem Url="docs/extensions/datagrid/api" Name="<DataGrid />" /> | ||
</DocsPageApi> |
This file contains 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 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 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.