admin管理员组文章数量:1304544
I have the following code:
$("#grid").kendoGrid({
dataSource: {
type: "odata",
data: scannedResult.targetList,
pageSize: 20
},
height: 550,
groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
columns: [{
field: "proccess",
title: "Contact Name",
width: 200
}, {
field: "status",
title: "status"
}, {
field: "ment",
title: "ment"
}]
});
creating a kendo simple grid. for detail here is my plunker.
now the field status
can be 1 of 3 values: passed, failed, skipped. I would like that the status
column will show an icon instead of the value. While the code for that is rather simple, i do not know how to make the column a custom column.
Is there a way to make a column a custom column?
I have the following code:
$("#grid").kendoGrid({
dataSource: {
type: "odata",
data: scannedResult.targetList,
pageSize: 20
},
height: 550,
groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
columns: [{
field: "proccess",
title: "Contact Name",
width: 200
}, {
field: "status",
title: "status"
}, {
field: "ment",
title: "ment"
}]
});
creating a kendo simple grid. for detail here is my plunker.
now the field status
can be 1 of 3 values: passed, failed, skipped. I would like that the status
column will show an icon instead of the value. While the code for that is rather simple, i do not know how to make the column a custom column.
Is there a way to make a column a custom column?
Share Improve this question edited Sep 15, 2015 at 22:07 OnaBai 40.9k6 gold badges97 silver badges125 bronze badges asked Aug 27, 2014 at 14:41 No Idea For NameNo Idea For Name 11.6k10 gold badges47 silver badges73 bronze badges2 Answers
Reset to default 7You should use a template definition. Something like:
- Define the template.
<script id="status-template" type="text/kendo-templ">
# if (data.status === 1) { #
<span>Status1</span>
# } else if (data.status === 2) { #
<span>Status 2</span>
# } else { #
<span>Status 3</span>
# } #
</script>
- Reference the template from the column definition
columns: [{
field: "proccess",
title: "Contact Name",
width: 200
}, {
field: "status",
title: "status",
template: $("#status-template").html()
}, {
field: "ment",
title: "ment"
}]
See it running here: http://jsfiddle/OnaBai/5x8wt0f7/
Obviously, the template can emit any HTML code, it might be links, images...
This has already been answered, but I want to show how I'd write this if people are confused when linking to jQuery selector.
// Custom Template that takes in entire Row object
function statusTemplate(dataRow) {
return `<span class="label label-${dataRow.status.toLowerCase()}">${dataRow.status}</span>`;
}
// Column definitions for grid
columns: [{
field: "proccess",
title: "Contact Name",
width: 200
}, {
field: "status",
title: "status",
template: statusTemplate
}, {
field: "ment",
title: "ment"
}]
http://jsfiddle/dentedio/hdokxme9/1/
本文标签: javascriptKendo Grid Custom ColumnStack Overflow
版权声明:本文标题:javascript - Kendo Grid Custom Column - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741788072a2397500.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论