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

Suppress Bound Column Editor in Create Mode

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chevron Phillips Chemical Co
Top achievements
Rank 1
Chevron Phillips Chemical Co asked on 04 Mar 2014, 07:14 PM
I have configured a grid’s bound column with an editor.  I would like the editor to be suppressed, or otherwise not available to the user, when creating a new row.  I’ve only thus far been able to use jQuery’s .html() function to empty the inner HTML, but there must be a more elegant solution.  Any attempts to replace the inner HTML with content result in that content becoming part of the editor (clickable to see the editor's dropdown).

What do you advise I do in the Edit event handler?

Reference Threads:
http://www.telerik.com/forums/column-readonly-in-edit-mode-but-editable-in-add-mode-
http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/editor-templates

--- CODE FOLLOWS ---

Here is the grid’s view model (showing the annotation):

public sealed class GridViewModel
{
   ...
   [UIHint("DisplayOrderEditor")]
   public Int32 DisplayOrder { get; set; }
}
 
Here is the editor template DisplayOrderEditor.cshtml:

@(Html.Kendo().DropDownList()
   .Name("DisplayOrder")
   .DataValueField("Value")
   .DataTextField("Text")
   .BindTo((IEnumerable<SelectListItem>)ViewData["displayorders"])
)
 
Here is the inline editable grid using AJAX for binding to remote data:

@(Html.Kendo().Grid<MyController.GridViewModel>()
   .Name("grid")
   .Columns(columns =>
   {
      ...
      columns.Bound(h => h.DisplayOrder);
   })
   .Editable(editable => editable.Mode(GridEditMode.InLine))
   .Events(events => events.Edit("onEdit"))
   .DataSource(dataSource => dataSource
      .Ajax()
      ...
)
 
Here is the handler for the Edit event:

function onEdit(e) {
   if (e.model.isNew() == true) {
      $('[name="DisplayOrder"]').parent().html("");
   }
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 06 Mar 2014, 08:50 AM
Hello,


There is no built in way to achieve this, so adding a custom check in the edit event is the way to go in the current case. Depending on the exact requirements you could disable, make readonly, remove etc. the editor input.

Let me know if I could assist you further on this topic.

Regards,
Dimiter Madjarov
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
Chevron Phillips Chemical Co
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or