Skip to content

Commit 1ac8c25

Browse files
kb(grid):Update on: Conditionally Hide Hierarchical Grid Expand Button (#747)
Co-authored-by: Nadezhda Tacheva <[email protected]>
1 parent f4c48ab commit 1ac8c25

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

knowledge-base/grid-conditional-expand-button.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,36 @@ res_type: kb
2222

2323

2424
## Description
25-
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.
2625

27-
I would like the expand to only be visible when it has further data to expand.
26+
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.
27+
28+
I would like the expand to only be visible when it has further data to expand.
2829

2930
## Solution
3031

31-
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).
32+
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).
3233

33-
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.
34+
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.
3435

3536
>caption Hide the expand button conditionally per row
3637
3738
````CSHTML
3839
@* Use CSS and the RowRender event to hide the detail template expand button conditionally *@
39-
4040
<style>
4141
/*
4242
A CSS rule that matches the OnRowRender handler to
43-
conditionally hide hierarchy expand buttons.
43+
conditionally hide hierarchy expand buttons and
44+
stops the pointer events of the cells with no
45+
expand buttons.
4446
You may want to add this to your site-wide stylesheet.
4547
*/
4648
.k-grid tr.no-children td.k-hierarchy-cell * {
4749
display: none;
4850
}
51+
52+
.k-grid tr.no-children td.k-hierarchy-cell {
53+
pointer-events: none;
54+
}
4955
</style>
5056
5157
<TelerikGrid Data="@salesTeamMembers" OnRowRender="@OnRowRenderHandler">
@@ -73,7 +79,7 @@ Then, if you want to hide the expand icon, set a CSS class to the row that will
7379
MainModel item = args.Item as MainModel;
7480
7581
bool hasNoHierarchy = item.Orders == null || item.Orders.Count == 0;
76-
args.Class = hasNoHierarchy ? "" : "no-children";
82+
args.Class = hasNoHierarchy ? "no-children" : "";
7783
}
7884
7985
// sample data generation follows

0 commit comments

Comments
 (0)