Making individual rows read-only

7 posts, 0 answers
  1. Ryan
    Ryan avatar
    8 posts
    Member since:
    Oct 2012

    Posted 12 Dec 2012 Link to this post

    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?
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 12 Dec 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Ryan
    Ryan avatar
    8 posts
    Member since:
    Oct 2012

    Posted 12 Dec 2012 Link to this post

    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 );
       }
  5. Piyush Bhatt
    Piyush Bhatt avatar
    17 posts
    Member since:
    Oct 2014

    Posted 20 Oct 2014 Link to this post

    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 
  6. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 22 Oct 2014 Link to this post

    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!
     
  7. Piyush Bhatt
    Piyush Bhatt avatar
    17 posts
    Member since:
    Oct 2014

    Posted 29 Oct 2014 Link to this post

    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 }
    }

  8. Piyush Bhatt
    Piyush Bhatt avatar
    17 posts
    Member since:
    Oct 2014

    Posted 29 Oct 2014 Link to this post

    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);
Back to Top
Kendo UI is VS 2017 Ready