Articles in this section
Category / Section

How to hide expand/collapse icon for groups with single item in JavaScript Grid?

3 mins read
While grouping columns some groups might have single item in them and for such cases, it is possible to hide the expand/collapse icon in JavaScript Grid. This can be achieved by setting the css icon content to empty for the groups with single items in the dataBound event.

Initially the element of groups with single item is returned which can be done using the title attribute value of the element. Then a new class is added to its previous sibling element which contains the icon class.


<script>
// DataBound event function
function OnDataBound(args) {
    // Returns element of groups with single item
    this.element.querySelectorAll('.e-gridcontent .e-table td[title*="1 item"]').forEach(el => {
         // New class is added to the element’s previous sibling
         el.previousSibling.classList.add("group-hide");
    });
}
</script>

 

Now based on the newly added class, the icon content is overridden with empty value.

<style>
// Overriding the icon content based on the added class
.group-hide .e-icons::before {
        content: '' !important;
}
</style>

 

Also, pointer events are set to none for this new class to prevent selection.

<style>
// Pointer events disabled for icon
.group-hide {
       pointer-events: none;
}
</style>

Output

Hide icon for groups with single item

JavaScript sample


Conclusion

I hope you enjoyed learning about how to hide expand/collapse icon for groups with single item in JavaScript Grid.

You can refer to our JavaScript Grid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Grid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied