-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The decorator appends or prepends content to the decorated control. It can be used to add additional rows to GridView
- Loading branch information
Showing
4 changed files
with
134 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using DotVVM.Framework.Hosting; | ||
using DotVVM.Framework.Binding; | ||
|
||
namespace DotVVM.Framework.Controls | ||
{ | ||
/// <summary> Adds a template before or after the decorated control. </summary> | ||
[ControlMarkupOptions(AllowContent = false)] | ||
public class AddTemplateDecorator: Decorator | ||
{ | ||
/// <summary> Template is rendered after the decorated control. </summary> | ||
[MarkupOptions(MappingMode = MappingMode.InnerElement)] | ||
public ITemplate After | ||
{ | ||
get => (ITemplate)GetValue(AfterProperty)!; | ||
set => SetValue(AfterProperty, value); | ||
} | ||
public static readonly DotvvmProperty AfterProperty = | ||
DotvvmProperty.Register<ITemplate, AddTemplateDecorator>(nameof(After)); | ||
|
||
/// <summary> Template is rendered before the decorated control. </summary> | ||
[MarkupOptions(MappingMode = MappingMode.InnerElement)] | ||
public ITemplate Before | ||
{ | ||
get => (ITemplate)GetValue(BeforeProperty)!; | ||
set => SetValue(BeforeProperty, value); | ||
} | ||
public static readonly DotvvmProperty BeforeProperty = | ||
DotvvmProperty.Register<ITemplate, AddTemplateDecorator>(nameof(Before)); | ||
|
||
protected internal override void OnInit(IDotvvmRequestContext context) | ||
{ | ||
var after = this.After; | ||
var before = this.Before; | ||
|
||
if (after is {}) | ||
{ | ||
Children.Add(new TemplateHost(after)); | ||
} | ||
if (before is {}) | ||
{ | ||
Children.Insert(0, new TemplateHost(before)); | ||
} | ||
} | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
src/Tests/ControlTests/testoutputs/GridViewTests.GridView_RowDecorators_AddChildren.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,40 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
|
||
<!-- ko if: Customers()?.Items()?.length --> | ||
<table data-bind="dotvvm-gridviewdataset: {'mapping':{},'dataSet':Customers()}"> | ||
<thead> | ||
<tr> | ||
<th> | ||
<span>Name</span> | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody data-bind="foreach: Customers()?.Items"> | ||
|
||
<!-- ko if: Enabled --> | ||
<tr colspan="3"> | ||
<td> | ||
˯˯˯ enabled customer ˯˯˯ | ||
</td> | ||
</tr> | ||
<!-- /ko --> | ||
<tr data-bind="css: { enabled: Enabled }"> | ||
<td> | ||
<span data-bind="text: Name"></span> | ||
</td> | ||
</tr> | ||
|
||
<!-- ko if: Enabled --> | ||
<tr colspan="3"> | ||
<td> | ||
˄˄˄ enabled customer ˄˄˄ | ||
</td> | ||
</tr> | ||
<!-- /ko --> | ||
</tbody> | ||
</table> | ||
<!-- /ko --> | ||
</body> | ||
</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