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

Checkbox in Grid

5 Answers 336 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jaime
Top achievements
Rank 1
Jaime asked on 27 Feb 2013, 05:33 PM
If I want to display a checkbox in the grid. Whats the best way to do that?

I am doing this and it doesn't seem to work.

@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Template(@<input type="checkbox" />);
columns.Bound(r => r.RouteName);
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(
false)
)
)

 

 

 

 

5 Answers, 1 is accepted

Sort by
0
Iliana Nikolova
Telerik team
answered on 28 Feb 2013, 03:14 PM
Hi Jaime,

In order to achieve this you should use ClientTemplate for the Grid's columns. For example: 
@(Html.Kendo().Grid(Model)
  .Name("Grid")
  .Columns(columns =>
  {
     columns.Template(p => { }).ClientTemplate("<input type='checkbox' class='checkbox'/> ");
     columns.Bound(r => r.RouteName);
  })
  //....
)

Regards,

Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ling Ling
Top achievements
Rank 1
answered on 07 Jan 2014, 09:02 PM
That worked, however, the check box is editable even when the grid is not in edit mode.  So I added disabled='disabled' 'checked=checked' in the template.  That worked for the boxes that are checked, but the 'unchecked' box is still editable.  how do you get around that?  thx
0
Iliana Nikolova
Telerik team
answered on 09 Jan 2014, 03:50 PM
Hello Ling,

In order to be able to edit only enabled checkboxes you could use the JavaScript conditional operator
//....
columns.Bound(p => {}).ClientTemplate("#= (//condition here//) ? \"<input type='checkbox' checked='checked'/>\" : \"<input type='checkbox' disabled='disabled' />\" #");

Regards,
Iliana Nikolova
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
SOLOMON
Top achievements
Rank 1
answered on 16 Jan 2014, 03:18 PM
Is it possible to display the Checkbox only in the inline edit mode and not any other time? Display some text the other time?
0
Iliana Nikolova
Telerik team
answered on 20 Jan 2014, 02:12 PM
Hello Solomon,

We have an online demo which demonstrates the described behaviour in action. 

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
Jaime
Top achievements
Rank 1
Answers by
Iliana Nikolova
Telerik team
Ling Ling
Top achievements
Rank 1
SOLOMON
Top achievements
Rank 1
Share this question
or