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

Grid Column Template javascript

1 Answer 228 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 28 Jun 2013, 01:36 AM
Hi

I'm trying to convert my site to utilise Kendo Grid, I'm trying to add a <div> that calls a javascript onClick using Column template but the javascript isn't being called. I suspect that it might have to do with how the data is loaded. Any idea on how I can add a clickable div through column template.

Also, how do i utilise Template instead of ClientTemplate ? what are the differences ?

<%: Html.Kendo().Grid<CIS.Models.Patients.PatientModel>()
      .Name("grid")
      .DataSource(dataSource => dataSource // Configure the grid data source
          .Ajax() // Specify that ajax binding is used
          .Read(read => read.Action("t1", "ttt")) // Set the action method which will return the data in JSON format
          .PageSize(25)
       )
      .Columns(columns =>
      {
          columns.Bound(p => p.ID).ClientTemplate(
              CIS.Models.Helpers.Controls.IconLink("Open", "ui-icon icon-folder-open", "ViewPatient", "Patients", new { patientID = "#= ID #" }) +
              "<div title=\"Edit\" class=\"ui-icon icon-pencil edit-patient-btn\" patientID=\"#= ID #\" style=\"display: inline-block\"> </div>"+
              "<div title=\"Remove\" class=\"ui-icon icon-trash remove-patient-btn\" patientID=\"#= ID #\" style=\"display: inline-block\"> </div>"
               
              ).Title("");
          columns.Bound(p => p.initials).Title("Initial");
          columns.Bound(p => p.dateOfBirth).Format("{0:dd/MM/yy}").Title("Date of Birth");
          columns.Bound(p => p.gender).Title("Gender");
 
      })
      .Pageable()
        .Sortable()
     
%>

1 Answer, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 01 Jul 2013, 03:42 PM
Hi David,

I am not quite sure what causes the problem in your application because from the provided code snippet it is not clear how you are attaching the click handler. Generally speaking you could use the onclick event to achieve the desired result: 
//....
columns.Bound(p => p.ProductName).ClientTemplate("<div title=\"Edit\" onclick=\"customFunction()\" //....> Edit</div>");
Please test the suggested solution and let me know if it works for you. Also, could you please provide more details about the custom helper?

Regarding Template / ClientTemplate - the Template method should be used when the Grid is server bound while ClientTemplate is suitable for Ajax bound Grid. For more detailed information take a look at this help article

Regards,
Iliana Nikolova
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
David
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Share this question
or