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

Change grid properties based on condition/role

0 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul Sheridan
Top achievements
Rank 1
Paul Sheridan asked on 24 Jul 2012, 08:11 AM
Hi All,

I was wondering if something I used frequently in the MVC suite is available in the framework release of the kendoui grid.

Basically I tend to vary the columns/edit function of a grid based on user role = Previously I would do something like this..


var grid = Html.Telerik().Grid<StaffRoleGridItem>()
        .Name("OStaffRoles")
            .DataBinding(db =>
            {
                db.Ajax()
                    .Select("_ListUsers", "Ajax", new { type = Model.Type });
            })
            .Columns(c =>
            {
                c.Bound(o => o.Id).Hidden();
                c.Bound(o => o.Name).Title("User/Group Name");
                c.Bound(o => o.Role).Title("Role in Project");
            });
                 
    if ((POModel.ViewMode)ViewBag.Mode == PMOBaseModel.ViewMode.CREATE)
    {
        grid
            .DataKeys(keys => keys.Add(o => o.Id))
            .ToolBar(cmd =>
                {
                    cmd.Insert().ButtonType(GridButtonType.Text).ImageHtmlAttributes(new { style = "margin-left: 0" }).Text("Add New Role");
                })
            .DataBinding(db =>
                {
                    db.Ajax()
                        .Insert("_InsertUser", "Ajax", new { type = Model.Type })
                        .Update("_EditUser", "Ajax", new { type = Model.Type })
                        .Delete("_DeleteUser", "Ajax", new { type = Model.Type });
                })
            .Columns(c =>
                {
                    c.Command(cmd =>
                    {
                        cmd.Edit().ButtonType(GridButtonType.Text);
                        cmd.Delete().ButtonType(GridButtonType.Text);
                    }).Width(190);
                })
            .Editable(e => e.Mode(GridEditMode.InLine))
            .ClientEvents(ev => ev.OnEdit("onRoleEdit"));
    }
    grid.Render();

Calling the .Render() function of the MVC grid late gives me the option to change its nature based on the roles attributed to the user.

Does anyone know of a method to do something similar to this in the clientside JS for the grid?

any help appreciated.

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Paul Sheridan
Top achievements
Rank 1
Share this question
or