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

I want to create a grid, but conditionally display a checkbox in some rows

1 Answer 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dan Harvey
Top achievements
Rank 2
Dan Harvey asked on 12 Feb 2014, 03:35 PM
Hey,

I am trying to use the framework but am having difficulties.  Im using the below code to populate the grid (like in the example, http://demos.telerik.com/kendo-ui/web/grid/index.html).

When I try to implement this code using a template to add a checkbox, it breaks.  How do i achieve this?


<script>
        
       $(document).ready(function () {
           $("#grid").kendoGrid({
               dataSource: {
                   type: "odata",
                   transport: {
                       read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Customers"
                   },
                   pageSize: 10
               },
               groupable: true,
               sortable: true,
               pageable: {
                   refresh: true,
                   pageSizes: true,
                   buttonCount: 5
               },
               columns: [{
                       field: "ContactName",
                       title: "Contact Name",
                       width: 140,
                       template: "#= checkbox(ContactTitle)"
                   }, {
                       field: "ContactTitle",
                       title: "Contact Title",
                       width: 190
                   }, {
                       field: "CompanyName",
                       title: "Company Name"
                   }, {
                       field: "Country",
                       width: 110
                   }]
           });
       });
        
       function checkbox(contactTitle) {
           if (contactTitle.length > 0) {
               return '<input type="checkbox" value="' + contactTitle + '" checked="checked" />';
           } else {
               return '<input type="checkbox" value="' + contactTitle + '" />';
           }
       }
 
   </script>
 
 
 
   <div id="grid" style="height: 380px" ></div>

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 13 Feb 2014, 07:22 AM
Hello Dan,

You are missing the closing hash `#` in the template definition: template: "#= checkbox(ContactTitle)#"

Here is a sample for this: http://jsbin.com/guyil/1/edit.

Regards,
Nikolay Rusev
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
Dan Harvey
Top achievements
Rank 2
Answers by
Nikolay Rusev
Telerik team
Share this question
or