From ceccc9ae136c5e32412ee55e4a272dae0ab4812c Mon Sep 17 00:00:00 2001 From: Nadezhda Tacheva Date: Fri, 28 Jan 2022 18:13:03 +0200 Subject: [PATCH] kb(grid):Update on: Conditionally Hide Hierarchical Grid Expand Button --- .../grid-conditional-expand-button.md | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/knowledge-base/grid-conditional-expand-button.md b/knowledge-base/grid-conditional-expand-button.md index 80cad8887b..508555cefd 100644 --- a/knowledge-base/grid-conditional-expand-button.md +++ b/knowledge-base/grid-conditional-expand-button.md @@ -22,30 +22,36 @@ res_type: kb ## Description -How would you remove the icon to expand a detail grid only for certain rows? Some rows will not have detail data and should not be expandable. -I would like the expand to only be visible when it has further data to expand. +How would you remove the icon to expand a detail Grid only for certain rows? Some rows will not have detail data and should not be expandable. + +I would like the expand to only be visible when it has further data to expand. ## Solution -Use the [`OnRowRender` event]({%slug grid-events%}#onrowrender) to evaluate the current row item (for example, whether it has child items in a collection or some other flag your application has). +Use the [`OnRowRender` event]({%slug grid-events%}#onrowrender) to evaluate the current row item (for example, whether it has child items in a collection or some other flag your application has). -Then, if you want to hide the expand icon, set a CSS class to the row that will hide the button in the expand cell. +Then, if you want to hide the expand icon, set a CSS class to the row that will hide the icon in the expand cell. It is also important to disable the pointer events of the cells with no expand icons, so the user cannot click them to open the empty child Grid even though the plus icon is hidden. >caption Hide the expand button conditionally per row ````CSHTML @* Use CSS and the RowRender event to hide the detail template expand button conditionally *@ - @@ -73,7 +79,7 @@ Then, if you want to hide the expand icon, set a CSS class to the row that will MainModel item = args.Item as MainModel; bool hasNoHierarchy = item.Orders == null || item.Orders.Count == 0; - args.Class = hasNoHierarchy ? "" : "no-children"; + args.Class = hasNoHierarchy ? "no-children" : ""; } // sample data generation follows