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

Making individual rows read-only

6 Answers 1176 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 12 Dec 2012, 04:03 PM
What is the best practice for making individual rows in a kendo grid read-only?  The ideal solution would mean that clicking a field in a read-only row would not produce an in-cell editor.  Is this currently supported?

6 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 12 Dec 2012, 05:47 PM
Hi Ryan,

Making individual rows read-only is not supported out of the box. It is possible to define individual columns as editable: false in the DataSource's model. When the user clicks on such field it will not enter in edit mode.

Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ryan
Top achievements
Rank 1
answered on 12 Dec 2012, 05:57 PM
Thanks for the response.  Hopefully Kendo will support this capability in the future.  In the meantime, here is what we are doing in the edit event handler of our grid to get around this limitation:

if ( e.model.get( "some-boolean-field-indicating-readonly" ) ) {
       var myNotEditableField = $( "input", e.container );
       var value = myNotEditableField.val();
       var $newInput = $( '<input type="hidden" name="MyNotEditableField" id="MyNotEditableField" value="" />' + '<span>' + value + '</span>' ).val( value );
       myNotEditableField.replaceWith( $newInput );
   }
0
Piyush Bhatt
Top achievements
Rank 1
answered on 21 Oct 2014, 02:41 AM
Telerik,

Is there any support of Read Only Row or Cell now based on conditions? For example, in above case, before the Cell creates the Editable Controls, it should call some method that that can throw TRUE/FALSE that a user can control.

This is highly desired feature.
-Piyush Bhatt 
0
Alexander Popov
Telerik team
answered on 22 Oct 2014, 10:40 AM
Hi Piyush,

Making individual rows or cells not editable is not supported, however it could be achieved using a custom solution. For example you can use a custom columns.editor function that renders either a static value or a widget depending on certain criteria. Here is an example how this could be achieved.

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Piyush Bhatt
Top achievements
Rank 1
answered on 29 Oct 2014, 01:53 PM
I can understand what you are trying via custom editor - and editor can possibly be used as well - though there has to be an option while using the editor - whether to use readonly editor or to use the default provided by kendo. Reason is, in the custom editor function we don't want to create the kendo widgets ourselves and let kendo handle it as its currently doing. something like below for the dojo link you sent

function categoryDropDownEditor(container, options) {
          if(options.model.Discontinued == true){ container.text(options.model.Category.CategoryName); } else { //let kendo handle this }
}

0
Piyush Bhatt
Top achievements
Rank 1
answered on 29 Oct 2014, 06:41 PM
Here is how I found that we can override the default behavior. So In editCell - we can put a check if the cell is read only or not before calling the default function. 

(function ($) {
    var editCell_base = kendo.ui.Grid.fn.editCell;
    kendo.ui.Grid.fn.editCell = function (cell) {
        //console.log('custom editCell called');
        if (cell.hasClass('some-class-read-only')) return;
        return editCell_base.apply(this, cell);
    }
})(jQuery);
Tags
Grid
Asked by
Ryan
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Ryan
Top achievements
Rank 1
Piyush Bhatt
Top achievements
Rank 1
Alexander Popov
Telerik team
Share this question
or