How to send an item via EditorViewData

2 posts, 0 answers
  1. Mateusz
    Mateusz avatar
    1 posts
    Member since:
    Jul 2014

    Posted 18 Sep Link to this post

    I have an editable grid with custom EditorTemplate, the grid has "InLine" edit mode. 

    I would like to send a property to this EditorTemplate by using EditorViewData. This property is assigned to the selected row. 

    @(Html.Kendo().Grid<VehicleWithTrackerDTO>()
                  .Name("VehiclesGrid")              
                  .Events(e => e
                        .ExcelExport("excelExport")
                        .BeforeEdit("getColor"))
                  .Columns(columns =>
                  {
    // LOOK AT THE FIRST LINE BELOW:
                      columns.Bound(d => d.ImageId).Title("Image").ClientTemplate("<img src='" + Url.Content("~/imgs/") + "#:Image#'/>").Width(120).Sortable(false).Filterable(false).EditorViewData(new { colorId = 1 });
    // colorId = 1 should be replaced with something like #:ColorId#
                      columns.Bound(d => d.Brand).Width(200).Filterable(fb => fb.Multi(true).Search(true));                   
                      columns.Command(command => { command.Edit(); }).Width(100);
                  })
                  .Editable(editable => editable.Mode(GridEditMode.InLine))           
                  .DataSource(source => source
                      .Ajax()
                      .Events(events => events.Error("errorHandler"))
                      .Model(model => model.Id(p => p.DeviceId))
                      .Read(read =>
                      {
                          read.Action("GetVehicles", "Vehicles").Data("searchQuery");
                      })
                      .Update(update => update.Action("Update", "Vehicles"))
                  )
          )

    My question is how can I send an item with "colorId" property? 

    My first idea was to create a javascript function, which will return data like this:

    function getColor(e) {
        return {
            colorId: e.model["ColorId"]
        };
    }

     

    But I can't see the solution to pass this data into EditorViewData method.

     

     

    Thanks, 

    Mateusz

  2. Stefan
    Admin
    Stefan avatar
    1138 posts

    Posted 21 Sep Link to this post

    Hello, Mateusz,

    I can suggest checking the following thread in our forum on the same subject. There are different approaches and some of them prove helpful based on the community feedback:

    http://www.telerik.com/forums/pass-grid-view-model-data-to-editor-template

    I hope this is helpful.

    Regards,
    Stefan
    Progress Telerik
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top