We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to turn grouping on/off via code

I am using this code with an external menu item to hide/show the grouping feature of the grid. The grid does not refresh to hide the grouping box at the top of the grid. I also tried the RefreshHeader() with the same result. 

GridResults.AllowGrouping = !GridResults.AllowGrouping;

Note, VS gives an warning that this property should not be set outside the component. 

I also have this same issue with this command: GridResults.PrintMode = PrintMode.AllPages;
In with print, I have two menu items; "Print this page", and "Print all pages". So need to also set these via code behind.

Thanks for the help!

1 Reply

RS Renjith Singh Rajendran Syncfusion Team December 19, 2019 10:27 AM UTC

Hi Scott, 

Thanks for contacting Syncfusion support. 

We suggest you to bind variables for these properties “AllowGrouping” and “PrintMode”, and modify those variables dynamically based on your requirement. We have prepared a sample to dynamically update these properties in a button click, please download the sample form the below link, 
Please refer the code below, 

<EjsGrid TValue="Order" ... AllowGrouping="@SetGroup" Toolbar="@(new List<string>() { "Print" })" PrintMode="@ChangeMode"> 
@code { 
   public bool SetGroup; 
    public PrintMode ChangeMode; 
    public void EnableGroup() 
        SetGroup = true; 
    public void DisableGroup() 
        SetGroup = false; 
    public void AllPrint() 
        ChangeMode = PrintMode.AllPages; 
    public void CurrentPrint() 
        ChangeMode = PrintMode.CurrentPage; 

Please get back to us if you need further assistance. 

Renjith Singh Rajendran. 

Live Chat Icon For mobile
Up arrow icon