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

[Solved] Disable edit for specific rows when using InCell editing

5 Answers 241 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
IT
Top achievements
Rank 1
IT asked on 02 Aug 2011, 08:52 AM
I have a grid which uses ajax binding and InCell edit mode.

I'd like to selectively prevent certain rows from being edited based on a value of the underlying dataItem.

I'm already successfully hiding the edit/delete buttons using the OnRowDataBound client event and $(e.row).find(".t-grid-edit, .t-grid-delete").hide(); as per another post I found... however I can't see how to disable edit.

I'd considered doing something in the OnRowDataBound event as with the command buttons, but I not sure what to do to the row to make it read only. I have the same issue if I look at using RowAction, and I'm not even sure this would be an option for client side.

I looked at the OnEdit event, but it doesn't seem to have a preventDefault() method like OnDelete or OnSave do.

Ideally I want it so that when the user clicks in an editable cell on a row that matches a specific criteria (to do with values in dataItem), that the event is cancelled and nothing happens (i.e. cell does not go into edit mode), other cells would of course behave as normal.

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 03 Aug 2011, 07:51 AM
Hello Aleks,

 The following should work:

function onRowDataBound(e) {
   if ( !editable(e.dataItem)) {
        $(e.row).find("td").click(function(e) {
               e.stopPropagation();
        });
   }
}
You just need to implement the editable function to return true or false based on the data item. You also need to subscribe to the OnRowDataBound event.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

0
FinallyInSeattle
Top achievements
Rank 1
answered on 17 Nov 2011, 04:00 AM
I just tried using this mechanism today with the latest version - 2011.3.1115.340.

I've subscribed to OnRowDataBound, but the event never fires (confirmed with debugger stmt).  I'm using InCell editing and I also have ".KeyboardNavigation(kbd => kbd.EditOnTab(true))". Are there any settings that would conflict with OnRowDataBound?  
0
Atanas Korchev
Telerik team
answered on 17 Nov 2011, 02:00 PM
Hi Finallyinseattle,

 OnRowDataBound will fire only if the grid is ajax bound (initially). Can you confirm that this is the case? OnDataBound will not be raised when the grid is server bound initially (and then making ajax requests).

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
FinallyInSeattle
Top achievements
Rank 1
answered on 17 Nov 2011, 06:51 PM
Hi Atanas,

Yes, that's the issue.  Is there another mechanism for disabling edits on a row?

Thanks!
0
Atanas Korchev
Telerik team
answered on 18 Nov 2011, 08:14 AM
Hello Finallyinseattle,

 You may configure your grid to make a request when display in order to avoid the server binding. Avoid passing the model in the grid constructor if you decide to do so:

<%: Html.Telerik().Grid<T>()
%>

 Or you can use the CellAction method to hide the command cell for the rows of interest.

All the best,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
IT
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
FinallyInSeattle
Top achievements
Rank 1
Share this question
or