# Preventing the User from Removing the Initial Groups, Changing their Order, or Adding New Groups

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Grid</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2023.3.1010 version</td>
 </tr>
</table>

## Description

How can I prevent the user from moving the initially added groups of the Grid, changing their order, or adding new groups?

## Solution

1. Create a Grid with initial groups.
2. Handle the [`Group`](https://docs.telerik.com/aspnet-mvc/api/kendo.mvc.ui.fluent/grideventbuilder#groupsystemstring) event of the Grid.
3. Within the `Group` event handler, get the current Grid groups by using the [`group()`](https://docs.telerik.com/kendo-ui/api/data/datasource/methods/group) method of the DataSource.
4. Check if the number of initial groups matches the number of current groups and if the first initial group matches the current first group and prevent the default event action if this condition is not met.

   ```Razor HtmlHelper
       @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
           .Name("grid")
           .Groupable()
           .Events(ev => ev.Group("onGroup"))
           .DataSource(dataSource => dataSource
               .Ajax()
               .Group(groups => 
               {
                   groups.Add(p => p.UnitsInStock);
                   groups.Add(p => p.UnitsOnOrder);
               })
               ...
           )
           ...
       )
   ```

   ```JS script
       <script>
           function onGroup(e) {
               var currentGroups = e.sender.dataSource.group(); // Get the current groups.
               if(currentGroups.length > 0) {
                   if((currentGroups.length != e.groups.length) || (currentGroups[0].field != e.groups[0].field)) { 
                       // Prevent the Group event.
                       e.preventDefault();
                   }
               }
           }
       </script>
   ```

For a runnable example based on the code above, refer to the [REPL example on preventing the user from removing or rendering the initial Grid groups or adding new groups](https://netcorerepl.telerik.com/wRlkcZkj4397B7E313).

## More ASP.NET MVC Grid Resources

* [ASP.NET MVC Grid Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/overview)

* [ASP.NET MVC Grid Demos](https://demos.telerik.com/aspnet-mvc/grid/index)

* [ASP.NET MVC Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/grid)

* [Server-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
