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

[Solved] Conditionally setting editable server-side

5 Answers 312 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dale
Top achievements
Rank 1
Dale asked on 30 Jan 2015, 08:39 PM
I'm building a grid in my .cshtml file, with InCell edit mode and a destroy command, but I want to conditionally disable the grid based on an app-wide SaveEnabled setting (wired up to a user's access).  No matter how I combine Editable.Enabled and Editable.Mode, it never seems to set editable.enabled in the generated javascript.

@(Html.Kendo().Grid<WebAreaGroupAccess>()<br>                .Name("areaGroupAccess")<br>                .Columns(col =><br>                {<br>                    col.Bound(g => g.ActiveDirectoryGroupId).Title("Group").Width("30%").EditorTemplateName("ActiveDirectoryGroup").ClientTemplate("<a class='StandardHyperlink' href=/CPQ-IFO/Admin/Groups/${ActiveDirectoryGroupId}>${ActiveDirectoryGroupId}</a>");<br>                    col.Bound(g => g.Description).Title("Group Description").Width("30%");<br>                    col.Bound(g => g.AccessLevel).Title("Access Type").Width("20%").EditorTemplateName("AccessLevel").ClientTemplate("#= AccessLevel == 0 ? 'Read-Only' : 'Read/Write' #");<br>                    col.Command(command => { command.Destroy(); }).Width("20%").Hidden(!Model.PageDataModel.SaveEnabled);<br>                })<br>                .Editable(edit =><br>                {<br>                    edit.Enabled(Model.PageDataModel.SaveEnabled);<br>                    edit.Mode(GridEditMode.InCell);<br>                })<br>                .ToolBar(toolbar => toolbar.Create())<br>                .Events(e => e.Edit("onEdit").Save("onSave").Remove("setSaveRequired"))<br>                .DataSource(ds => ds<br>                    .Ajax()<br>                    .Batch(true)<br>                    .ServerOperation(false)<br>                    .Read(read => read.Action("AreaGroup_List", "Area", new { AreaCode = Model.Area.WebAreaCode }))<br>                    .Create(update => update.Action("AreaGroup_Create", "Area"))<br>                    .Update(update => update.Action("AreaGroup_Update", "Area"))<br>                    .Destroy(update => update.Action("AreaGroup_Delete", "Area"))<br>                    .PageSize(10)<br>                    .Model(m =><br>                    {<br>                        m.Id(g => g.ActiveDirectoryGroupId);<br>                        m.Field(g => g.ActiveDirectoryGroupId).DefaultValue("LNA-ISOURCE_ACCOUNT_ADMIN");<br>                        m.Field(g => g.Description).Editable(false);<br>                        m.Field(g => g.AccessLevel);<br>                        m.Field(g => g.WebAreaCode);<br>                    })<br>                    .Events(e => e.Sync("onSync").Error("onError"))<br>                )<br>            )

When SaveEnabled is false, the command column gets hidden, but the Access Level column is still editable.  Here's the generated javascript for editable:

"editable":{"confirmation":"Are you sure you want to delete this record?","confirmDelete":"Delete","cancelDelete":"Cancel","mode":"incell","template":null,"create":true,"update":true,"destroy":true}

5 Answers, 1 is accepted

Sort by
0
Dale
Top achievements
Rank 1
answered on 30 Jan 2015, 08:46 PM
Formatting was bad... here's a screenshot.
0
Dale
Top achievements
Rank 1
answered on 30 Jan 2015, 08:49 PM
The SetDefaults is an extension method I added to set default settings on all grids in our app (pageable, sortable, filterable, etc).  I also want to set editable.Enabled in there based on the SaveEnabled setting, but removed it in case that was causing the issue.  That didn't help, though.  Even when I set edit.Mode(false), I can still click into the cell and edit.
0
Nikolay Rusev
Telerik team
answered on 03 Feb 2015, 04:13 PM

Hello Dale,

I've just modified this demo on my end with following setting and it work correctly. Clicking on the cells doesn't allow the user to edit.

.Editable(editable => editable.Mode(GridEditMode.InCell).Enabled(false))

Can you wrap an example demonstrating the behavior that you are experiencing? Thus we'll be able to debug it locally and assist you further.

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Dale
Top achievements
Rank 1
answered on 03 Feb 2015, 05:57 PM
Ok, I setup a demo using a new Telerik MVC project.  I only modified the 3 attached files (added TestModel).  I tried both methods of combining edit.Mode and edit.Enabled (what's in the file + your syntax), and neither worked.  Both ID and Description columns are both editable.  Here's the generated javascript:

"editable":{"confirmation":"Are you sure you want to delete this record?","confirmDelete":"Delete","cancelDelete":"Cancel","mode":"incell","template":null,"create":true,"update":true,"destroy":true}


I'm using Kendo version 2014.3.1314.
0
Nikolay Rusev
Telerik team
answered on 05 Feb 2015, 12:30 PM

Hello Dale,

 

I was able to replicate the behavior. It is due to the fact that Destroy command internal implementation requires editing and enables it. Another important bit is that calling Enabled before setting the mode will also enable editing.

 

Here is how the setup should be in order to disabled editing:

    .Columns(col =>
    {
        col.Bound(c => c.ID);
        col.Bound(c => c.Description);
        col.Command(c => c.Destroy());
    })    
    .Editable(edit=>{
        edit.Mode(GridEditMode.InCell);
        edit.Enabled(false);
    }) 

 

 

Regards,
Nikolay Rusev
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
Dale
Top achievements
Rank 1
Answers by
Dale
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or