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

How to send an item via EditorViewData

1 Answer 1337 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mateusz
Top achievements
Rank 1
Mateusz asked on 18 Sep 2017, 01:24 PM

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 "" 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

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 21 Sep 2017, 06:20 AM
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.
Tags
Grid
Asked by
Mateusz
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or