Unplanned
Last Updated: 04 Nov 2020 15:24 by ADMIN
Ken
Created on: 09 May 2019 08:51
Category: Grid
Type: Feature Request
9
Add the ability to use a function to show/hide toolbar buttons like it is for column commands

Hi,

The Kendo UI Grid has the ability to conditionally hide/show the command columns. But in order to hide some buttons from the toolbar, you need a dataBound handler. It will be useful to hide the "Create" button from non-admins, but be able to show the PDF and Excel Export or hide the entire toolbar.

toolbar: [
    { name: "create", visible:function(){ return isAdmin; } },
    { name: "reports" , visible: function(){ return isManager }},
    { name: "cancel" }
  ],

Currently, we need to use this dataBound handler:

.Events(e=>e.DataBound("onDataBound"))     
  
 function onDataBound(e) {
   if (true) { // the condition against which you want to show/hide the toolbar
     this.element.find(".k-grid-toolbar").hide(); // hides the entire toolbar
     this.element.find(".k-grid-add").hide(); // hides just the Create button
  }
}


Thank you in advance,
Ken

2 comments
ADMIN
Alex Hajigeorgieva
Posted on: 04 Nov 2020 15:24

Hi,

For the ASP.NET MVC and Core Grid, we can add a condition:

@{
        // check if the user should have access
	var isAdmin = false;
}

.ToolBar(t =>
{
         if (isAdmin)
         {
             t.Create();
             t.Pdf();
         }
         else
         {
             t.Pdf();
         }
})

The other option is to use a ToolBar template and pass a condition there. This approach is also valid for the jQuery Grid:

http://demos.telerik.com/aspnet-mvc/grid/toolbar-template

I will mark this item as Unplanned and if it gains enough popularity, the Product Management team will consider it for future implementation.

Thank you both for taking the time to share your thoughts.

Regards,
Alex Hajigeorgieva
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Brightstar
Posted on: 28 Oct 2020 18:39
Would be nice if you could do it for the whole toolbar as well as item by item.