Grid column conditional editor

4 posts, 0 answers
  1. DJo
    DJo avatar
    23 posts
    Member since:
    Nov 2012

    Posted 20 Aug 2013 Link to this post

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

    Posted 22 Aug 2013 Link to this post

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

    Posted 22 Aug 2013 Link to this post

    I think your example doesn't work (there is no output), but your point is made.

    Thanks very much!!
  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 26 Aug 2013 Link to this post

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