简体   繁体   中英

How can I get the model data from my event sender data for specific selected row?

In my kendo grid, I have this Event attached:

.Events(events => events.DataBound("Planning.reSelectMeasurements('#=Label#')"))

From kendo grid:

 @(Html.Kendo().Grid<PlanningViewParam>().Name("Planning")
      .ClientRowTemplate(
     // INSERT HTML AND JS HERE
      )
      .DataSource(datasource => datasource.Ajax().Batch(false)
          .ServerOperation(false)
          .Read(read => read.Action("ReadMeasurements", "Planning", new { viewType = "A" }))
          .Model(model =>
          {
              model.Id(p => p.Order);
              model.Field(p => p.Label).Editable(false);
              model.Field(p => p.Color).Editable(false);
          })).Pageable(p=>p.Enabled(false))
              .HtmlAttributes(new { style = "height:202px; width:225px;",@class = "light-list-box"})
              .Scrollable(scrollable => scrollable.Height(100).Virtual(false))
         .Selectable(selectable => selectable
            .Mode(GridSelectionMode.Single)
            .Type(GridSelectionType.Row))
         .Events(events => events.DataBound("Planning.reSelectMeasurements('#=Label#')"))

Is it possible to pass information from my view model to this function instead of the literal string return? I noticed when I ran firebug and I put a breakpoint next to the function, it says label gets passed in as "#=Label#".

Where:

reSelectMeasurements: function (label) {
            if (label == "Point") {
                Planning.reSelectPoint("A");
            }
            else if (label == "Angle") {
                Planning.reSelectAngle("A");
            }
        }

EDIT:

Latest attempt:

 if (events.sender._data.PointLabel == "Point") {
                Planning.reSelectPoint("A");
            }
            else if (events.sender._data.Label == "Angle") {
                Planning.reSelectAngle("A");
            }

when I get to _data. on debugging, it contains an array of data. How do I pass in the specific row I selected in so that I can pass in the proper Label data?

so the hierarchy looks something like events.sender._data.[0].Label ?

I think this depends upon the version of the controls, but in 2014.2.903.545 this is how i pass data from the grid to a javascript function.

in razor: ...

 .Events(e =>
               {
               e.Edit("readonlyifyKey");
               e.DataBound("bindMigrateButton");
               })

...

Then the function looks like this:

 function bindMigrateButton(e) {

    var prjId = e.sender.element.context.id;
    prjId = prjId.replace('projects-setttings_', '');
    $('#import-config-btn__' + prjId).click(showImportWindow);

}

prjId holds the model id of my object im binding to the grid, so you should be able to access any property of your model in this fashion.

It looks like var prjId = e.sender.element.context.id; is actually getting the dom element id, but you should still be able to access all the model elements off of e.sender , not exactly sure how its nested from there but the sender should have the model attributes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM