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

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

3 Answers 762 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 04 Mar 2013, 02:14 PM
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.

3 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 06 Mar 2013, 11:43 AM
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!
0
Andrew
Top achievements
Rank 1
answered on 06 Mar 2013, 12:25 PM
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({
                ...
            });
    }
}
0
Dimiter Madjarov
Telerik team
answered on 06 Mar 2013, 04:51 PM
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!
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or