This is a migrated thread and some comments may be shown as answers.

MVC Wrappers: CRUD operations enabled via model properties

3 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 17 May 2015, 04:09 AM

Using MVC wrappers, I would like to be able to show/hide the CRUD operations based on booleans in the model (CanCreate, CanUpdate, CanDelete). So, if the CanDelete property is true, the delete button should show up (if false, it should not). Same for other 2 properties.

How can I configure the MVC wrapper this way?

For example,

.ToolBar(commands => commands.Create())

should only be included if the Model.CanCreate is true.

Thanks,

--John

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 19 May 2015, 03:19 PM

Hello John,

A possible way to hide the create button in the toolbar is to set a class to the button element and apply the following style: 

 

@{
    bool isHidden = true;
     
}

.ToolBar(toolbar => { toolbar.Create().HtmlAttributes(new { @class = isHidden ? "hidden" : ""}); })
<style>
    .hidden {
        display: none;
    }
</style>


 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
John
Top achievements
Rank 1
answered on 06 Jun 2015, 09:06 PM

Hi Boyan,

I've tried this, and while it does hide the create button, it still leaves the toolbar div (k-header k-grid-toolbar k-grid-top) above the column headers, which looks out of place to have a blank space up there above the column headers. How can I show/hide the toolbar if I want to dynamically specify whether the user can create or not?

Thanks,

--John

0
Boyan Dimitrov
Telerik team
answered on 09 Jun 2015, 12:41 PM

Hello John,

In this case I would suggest hiding the toolbar container when the "Add new item" button is not visible. Please refer to the code snippet below:

function dataBinding(e) {
        if ($("#grid .k-grid-add").hasClass("hidden")) {
            $(".k-header.k-grid-toolbar.k-grid-top").hide();
        }
    }

I used the dataBinding event for testing purposes. 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
John
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
John
Top achievements
Rank 1
Share this question
or