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

Grid column conditional editor

3 Answers 726 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DJo
Top achievements
Rank 1
DJo asked on 20 Aug 2013, 04:21 PM
Hi;

I've got a grid and I want to have a custom editor in one column under certain conditions, and have no editor under other conditions. Building the editor without the conditions is trivial, but I cannot figure out how to do it conditionally.

Let me be specific: I want to have a dropdown editor in one column if the related dataItem has a value of "true" in another of its fields, and no editor if the value is "false".

I think it should be something like this:
{
  field: "ID",
  title: "Title",
  template: "#=TITLE#",
  editor: function () {
    if (RELATED) {
      MyEditor
    } else {
    }
  }
}
In this example the column with the editor uses the MyEditor function to create the editor. This works great without the conditional code, but fails with it. Essentially if the value of the dataItem field "RELATED" is true I want the editor, and otherwise I want no editor.

3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 22 Aug 2013, 11:20 AM
Hi David,

When using a custom editor the default editor is removed and you have to provide a new one, even if the requirements for the custom one are not met. For convenience I prepared a small example demonstrating such behavior and uploaded it in this jsBin.
 

Kind 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
DJo
Top achievements
Rank 1
answered on 22 Aug 2013, 03:03 PM
I think your example doesn't work (there is no output), but your point is made.

Thanks very much!!
0
Alexander Popov
Telerik team
answered on 26 Aug 2013, 12:44 PM
Hi David,

Apologise if I was not clear - the previous example displays custom editor for items which have a Discontinued field equal to true and a standard editor for the rest, however current solution works only when InCell edit mode is used. Here is an updated version of the demo, with the Edit command removed.


 Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
DJo
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
DJo
Top achievements
Rank 1
Share this question
or