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

this.dataItem($(e.currentTarget).closest("tr")); on custom command does not work when passing in model

1 Answer 1102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Liza
Top achievements
Rank 1
Liza asked on 29 Oct 2012, 09:53 AM
I am using custom commands and trying to get the selected dataitem. I am getting an error inside 
the javascript call on this.dataitem
By debugging in chrome i can see that the this.data is not populated on binding directly to a model. 
Where as in the telerik examples it is populated.
This is my code:
@using Kendo.Mvc.UI
  @{
     var addressList = Model.DataList as List<Intelli.Data.Parties.EFDAL.Entity.GeoAddress>;
   }
 
<script type="text/javascript">
  function viewgeoaddress(e) {
         //prevent the request which will be made by default
         e.preventDefault();
 
        //error occurs here!!
         var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
          
 
         }
     };
</script>
 
 
 @(Html.Kendo().Grid(addressList)
    .Name("GridPartyGeoAddresses")
    .Columns(columns =>
            {
                columns.Bound(p => p.ID).Title("ID").Hidden(true);
                columns.Bound(p => p.Address).Title("Address").Width(160);
                columns.Bound(p => p.Region).Title("Region").Width(80);
 
                columns.Bound(p => p.Zipcode).Title("Zipcode").Width(80);
                columns.Command(commands => commands
                                                .Custom("btnviewgeoaddress")
                                                .Text("View")
                                                .Click("viewgeoaddress")
                                                .HtmlAttributes(new { style = "text-align: center" }));
                columns.Command(commands => commands
                                                .Custom("btndeletegeoaddress")
                                                .Text("Remove")
                                                .Click("deletegeoaddress")
                                                .HtmlAttributes(new { style = "text-align: center" }));               
                 
 
            })
 
    .Scrollable(scr => scr.Enabled(true).Height(300))
    .Sortable(builder => builder.Enabled(true))
    .Resizable(resizing => resizing.Columns(true))
    //.Selectable()
    //                .DataSource(dataSource => dataSource
    //                                              .Ajax()
    //                                               .ServerOperation(false)
 
    //                    )
     
    )
 
 

1 Answer, 1 is accepted

Sort by
0
Accepted
Vladimir Iliev
Telerik team
answered on 01 Nov 2012, 10:34 AM
Hi Liza,

From the provided information it seems that the Grid currently use ServerBinding, in which the data on the client side is rendered directly into the Grid rows. You should enable Ajax binding to use the dataItem method or find the needed cell and get it's data using jQuery Html method

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Liza
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or