Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/data/app/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "plc-debug",
"request": "launch",
"program": "${workspaceFolder}",
"ip": "10.10.10.120",
"ip": "192.168.100.1",
"username": "${env:AX_USERNAME}",
"password": "${env:AX_TARGET_PWD}",
"certificate": "${workspaceFolder}\\certs\\plc_line\\plc_line.cer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@
</div>
<div class="card-body">
//<CustomColumns>
<DataExchangeView Vm="@_vm_columndata" Presentation="Command">
<ColumnData HeaderName="Some data" BindingValue="SomeString" Clickable="false" />
<ColumnData HeaderName="A number" BindingValue="SomeInt" Clickable="false" />
<ColumnData HeaderName="Yes/No" BindingValue="SomeBool" Clickable="false" />
<DataExchangeView Vm="@_vm_columndata" Presentation="Command">
<ColumnData HeaderName="Some data" BindingValue="SomeString" Clickable="false" />
<ColumnData HeaderName="A number" BindingValue="SomeInt" Clickable="false" />
<ColumnData HeaderName="Yes/No" BindingValue="SomeBool" Clickable="false" PresentationTemplate="@typeof(CustomBoolTemplate)" />
</DataExchangeView>
//</CustomColumns>
</div>
Expand Down Expand Up @@ -80,9 +80,9 @@
<div class="card-body">
//<Sorting>
<DataExchangeView Vm="@_vm_columndata" Presentation="Command" EnableSorting="true" SortElements='new() {"SomeData"}'>
<ColumnData HeaderName="Some data" BindingValue="SomeString" Clickable="false" />
<ColumnData HeaderName="Some data" BindingValue="SomeString" Clickable="false" />
<ColumnData HeaderName="A number" BindingValue="SomeInt" Clickable="false" />
<ColumnData HeaderName="Yes/No" BindingValue="SomeBool" Clickable="false" />
<ColumnData HeaderName="Yes/No" BindingValue="SomeBool" PresentationTemplate="@typeof(CustomBoolTemplate)" />
</DataExchangeView>
//</Sorting>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/data/app/ix-blazor/librarytemplate.blazor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
// ...

// Or collect them automatically using reflection:
distributedDataService.CollectAxoDataExchanges(Entry.Plc.AxoDataDistributedContext);
distributedDataService.CollectAxoDataExchanges(Entry.Plc.AxoDataDistributedContext.ControlledUnit_1);
distributedDataService.CollectAxoDataExchanges(Entry.Plc.AxoDataDistributedContext.ControlledUnit_2);

//</CollectingExchanges>

Expand Down
15 changes: 13 additions & 2 deletions src/data/docs/COLUMNS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Custom columns
# Custom Columns

There is a possibility to add custom columns if it is needed. You must add `AXOpen.Data.ColumnData` view as a child in `DataView`. The `BindingValue` must be set in `ColumnData` and contains a string representing the attribute name of custom columns. If you want to add a custom header name, you can set the name in `HeaderName` attribute. Also, there is an attribute to make the column not clickable, which is clickable by default. The example using all attributes:
It is possible to add custom columns if needed. Add an `AXOpen.Data.ColumnData` view as a child of the `DataView`.

- `BindingValue` (required): A string representing the member path in the POCO object.
- `HeaderName`: Sets the column header text. The default value is equal to `BindingValue`.
- `PresentationTemplate`: The type of presentation template used to display the value. Template must inherits from AXOpen.Data.ColumnDataCellBase. It will be populated with the POCO value. By default, the value is presented as a string.
- `Clickable`: Determines whether the column is clickable. The default is **clickable**.

---

[!code-smalltalk[](../app/ix-blazor/librarytemplate.blazor/Pages/Rendering.razor?name=CustomColumns)]

Expand All @@ -15,3 +22,7 @@ When adding data view manually, you will need to create ViewModel:

> [!NOTE]
> In `AxoDataFragmentExchange`, `Custom columns` can only be added from master fragment (the first declared repository).



[!include[](ColumnCellTemplate.md)]
16 changes: 16 additions & 0 deletions src/data/docs/ColumnCellTemplate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Column cell template (Blazor)

When creating column configurations, you can assign a custom Razor template to render a specific value.
The template will receive the property value of the POCO and display it as needed.

Customn template must inherits from `AXOpen.Data.ColumnDataCellBase`.

> [!IMPORTANT]
> Column cell template receive the value via the `PropertyValue` parameter, which is of type `object`.
> To safely work with the expected type, cast the value inside the component’s `OnParametersSet()` method.

---

### 🎨 Template example

[!code-csharp[ColumnRazorTemplate](../app/ix-blazor/librarytemplate.blazor/Templates/CustomBoolTemplate.razor)]
11 changes: 1 addition & 10 deletions src/data/docs/DistributedDataExchange_ColumnData.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ As shown in the example below, you can also specify a custom template for each c

[!code-csharp[ConfigurationOfColumnService](../app/ix-blazor/librarytemplate.blazor/Program.cs?name=AxoDataExchangeConfigurationService)]

> [!IMPORTANT]
> Column templates receive the value via the `PropertyValue` parameter, which is of type `object`.
> To safely work with the expected type, cast the value inside the component’s `OnParametersSet()` method.

---

### 🎨 Custom Column Template

When creating column configurations, you can assign a custom Razor component to render a specific column.
The component will receive the property value of the POCO and display it as needed:
[!include[](ColumnCellTemplate.md)]

[!code-csharp[ColumnRazorTemplate](../app/ix-blazor/librarytemplate.blazor/Templates/CustomBoolTemplate.razor)]
Binary file modified src/data/docs/assets/CustomColumns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@namespace AXOpen.Data

@code {
[Parameter]
public string HeaderName { get; set; }
[Parameter, EditorRequired]
public string BindingValue { get; set; }

[Parameter]
public string BindingValue { get; set; }
public string HeaderName { get; set; }

[Parameter]
public bool Clickable { get; set; } = true;
Expand All @@ -14,7 +14,20 @@
public DataExchangeView DataView { get; set; }

[Parameter]
public Func<object, RenderFragment> TemplateBuilder { get; set; }
public Type PresentationTemplate { get; set; }


private Func<object, RenderFragment> _builder;

public RenderFragment RenderTemplateWithValue(object value)
{
if (_builder == null)
{
_builder = ColumnDataCellBaseExtension.GetRenderFragment(PresentationTemplate);
}

return _builder.Invoke(value);
}

protected override void OnInitialized()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ else
if (column.Clickable)
{

@if (column.TemplateBuilder != null)
@if (column.PresentationTemplate != null)
{
// insert template
<td data-bs-toggle="modal" href="#viewModal-@ViewGuid" style="cursor: pointer" @onclick="() => Vm.SelectedRecord = item">@column.TemplateBuilder.Invoke(propertyValue)</td>
<td data-bs-toggle="modal" href="#viewModal-@ViewGuid" style="cursor: pointer" @onclick="() => Vm.SelectedRecord = item">@column.RenderTemplateWithValue(propertyValue)</td>

}
else
Expand All @@ -198,10 +198,10 @@ else
}
else
{
@if (column.TemplateBuilder != null)
@if (column.PresentationTemplate != null)
{
// insert template
<td> @column.TemplateBuilder.Invoke(propertyValue)</td>
<td> @column.RenderTemplateWithValue(propertyValue)</td>
}
else
{
Expand All @@ -227,10 +227,10 @@ else
var propertyValue = PropertyHelper.GetPropertyValue(item, column.BindingValue);
if (column.Clickable)
{
@if (column.TemplateBuilder != null)
@if (column.PresentationTemplate != null)
{
// insert template
<td style="cursor: pointer" @onclick="() => Vm.SelectedRecord = item">@column.TemplateBuilder.Invoke(propertyValue)</td>
<td style="cursor: pointer" @onclick="() => Vm.SelectedRecord = item">@column.RenderTemplateWithValue(propertyValue)</td>
}
else
{
Expand All @@ -240,10 +240,10 @@ else
else
{

@if (column.TemplateBuilder != null)
@if (column.PresentationTemplate != null)
{
// insert template
<td> @column.TemplateBuilder.Invoke(propertyValue)</td>
<td> @column.RenderTemplateWithValue(propertyValue)</td>
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ else
<ColumnData HeaderName="@column.ColumnName"
BindingValue="@column.BindingValuePath"
Clickable="@column.ClickEnabled"
TemplateBuilder="@ColumnDataCellBaseExtension.GetRenderFragment(column.TemplateType)"></ColumnData>
PresentationTemplate="@column.TemplateType"></ColumnData>
}

</DataExchangeView>
Expand Down