How to make cell editable based on value of another cell in grid?

4 posts, 0 answers
  1. Andrew
    Andrew avatar
    8 posts
    Member since:
    Jul 2011

    Posted 04 Mar 2013 Link to this post

    In my application, I need to be able to disable (make unedtiable) a cell based on the value of another cell in the same row.
    How can I achieve this using the Kendo UI grid?

    Currently, all I can figure out how to do is set the editable attribute for an entire column. But this won't work for me because I need to have some cells in that column be editable while others are not.

  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    1070 posts
    Member since:
    Jan 2013

    Posted 06 Mar 2013 Link to this post

    Hi Andrew,

     
    This functionality is not supported out of the box. It can be achieved, but the implementation will depend on the current edit mode. For example in Batch edit mode, you could attach to the edit event and check the
    model values in the event handler.

    E.g.

    function onEdit(e){
        if(e.model.UnitPrice > 10){
            this.closeCell();
        }
    }

    Please let me know if this covers your scenario or I can assist you further.

    Regards,
    Dimiter Madjarov
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!

  3. Andrew
    Andrew avatar
    8 posts
    Member since:
    Jul 2011

    Posted 06 Mar 2013 Link to this post

    That kind of works, but I would have to determine which column was currently being edited, I'm not sure how to do that.

    I found another way though. The column where I want this behavior has an editor function specified, so in that function I can check the model data and skip creating a control/editor if I want.

    function unitTypeEditor(container, options) {
        var type = options.model.Type;
        if (type.indexOf("Press.") < 0)
        {
            $('<input data-bind="value:' + options.field + '"/>')
                .appendTo(container)
                .kendoDropDownList({
                    ...
                });
        }
    }

  4. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    1070 posts
    Member since:
    Jan 2013

    Posted 06 Mar 2013 Link to this post

    Hello Andrew,

    To get the currently edited cell you could use the e.container object from the edit event arguments.

    E.g.

    <script>
      function onEdit(e) {
          var cell = e.container;
      }
    </script>


    Kind regards,
    Dimiter Madjarov
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!

Back to Top