Skip to content

Commit

Permalink
Merge pull request #1826 from riganti/column-visible-resource
Browse files Browse the repository at this point in the history
Support resource binding in GridViewColumn.Visible
  • Loading branch information
tomasherceg authored Jun 21, 2024
2 parents 0608724 + a2410a4 commit 9d053d0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Framework/Framework/Controls/GridViewColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public static readonly DotvvmProperty WidthProperty
= DotvvmProperty.Register<string?, GridViewColumn>(c => c.Width, null);

[PopDataContextManipulation]
[MarkupOptions(AllowHardCodedValue = false)]
[MarkupOptions]
public bool Visible
{
get { return (bool)GetValue(VisibleProperty)!; }
Expand Down
8 changes: 4 additions & 4 deletions src/Framework/Framework/Controls/TableUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DotVVM.Framework.Binding;
using DotVVM.Framework.Binding.Expressions;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -13,13 +14,12 @@ public class TableUtils
/// Hides entire column in the table. Should be applied to the header.
/// Does not check for correct usage, may give JS errors, check out the console if it does not work.
/// </summary>
[MarkupOptions(AllowHardCodedValue = false)]
[MarkupOptions]
public static readonly DotvvmProperty ColumnVisibleProperty
= DelegateActionProperty<bool>.Register<TableUtils>("ColumnVisible", (writer, context, property, control) =>
{
var binding = control.GetValueBinding(property);
if (binding != null)
writer.AddKnockoutDataBind("dotvvm-table-columnvisible", binding.GetKnockoutBindingExpression(control));
var value = control.GetValueOrBinding<bool>(property);
writer.AddKnockoutDataBind("dotvvm-table-columnvisible", value.GetJsExpression(control));
}, defaultValue: true);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
<dot:GridView DataSource="{value: CustomersDataSet}" class="table table-bordered">
<Columns>
<dot:GridViewTextColumn HeaderText="Id" ValueBinding="{value: CustomerId}" CssClass="{value: CustomerId % 2 == 0 ? 'alternate' : ''}" AllowSorting="True" IsEditable="false" />
<dot:GridViewTextColumn HeaderText="Name" ValueBinding="{value: Name}" AllowSorting="True" />
<dot:GridViewTextColumn HeaderText="Name" ValueBinding="{value: Name}" AllowSorting="True" Visible="true" />
<dot:GridViewTextColumn HeaderText="Birth Date" ValueBinding="{value: BirthDate}" FormatString="g" AllowSorting="True" Visible="{value: IsBirthDateVisible}" />
<dot:GridViewTextColumn HeaderText="Always hidden" ValueBinding="{value: Name}" Visible={resource: false} />
</Columns>
</dot:GridView>

Expand All @@ -36,4 +37,4 @@
</table>
</div>
</body>
</html>
</html>
11 changes: 11 additions & 0 deletions src/Samples/Tests/Tests/Control/GridViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,12 @@ public void Control_GridView_ColumnVisible()
AssertUI.IsDisplayed(browser.ElementAt("table", 1).ElementAt("tr", i).ElementAt("td,th", 1));
}
// column 3 is always hidden
for (int i = 0; i < 6; i++)
{
AssertUI.IsNotDisplayed(browser.ElementAt("table", 0).ElementAt("tr", i).ElementAt("td,th", 3));
}
// check that columns are hidden
browser.First("input[type=checkbox]").Click();
for (int i = 0; i < 6; i++)
Expand All @@ -527,6 +533,11 @@ public void Control_GridView_ColumnVisible()
{
AssertUI.IsNotDisplayed(browser.ElementAt("table", 1).ElementAt("tr", i).ElementAt("td,th", 1));
}
// column 3 is always hidden
for (int i = 0; i < 6; i++)
{
AssertUI.IsNotDisplayed(browser.ElementAt("table", 0).ElementAt("tr", i).ElementAt("td,th", 3));
}
// check that columns are visible again
browser.First("input[type=checkbox]").Click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,7 @@
"$type": "DotVVM.Framework.Compilation.ControlTree.PopDataContextManipulationAttribute, DotVVM.Framework",
"TypeId": "DotVVM.Framework.Compilation.ControlTree.PopDataContextManipulationAttribute, DotVVM.Framework"
},
"defaultValue": true,
"onlyBindings": true
"defaultValue": true
},
"Width": {
"type": "System.String",
Expand Down Expand Up @@ -1527,7 +1526,6 @@
"ColumnVisible": {
"type": "System.Boolean",
"defaultValue": true,
"onlyBindings": true,
"isActive": true
}
},
Expand Down

0 comments on commit 9d053d0

Please sign in to comment.