Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo Grid 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: "comment",
                title: "comment"
            }]
        });

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 statuscolumn 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?

like image 837
No Idea For Name Avatar asked Feb 12 '23 04:02

No Idea For Name


1 Answers

You 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: "comment",
            title: "comment"
        }]

See it running here: http://jsfiddle.net/OnaBai/5x8wt0f7/

Obviously, the template can emit any HTML code, it might be links, images...

like image 109
OnaBai Avatar answered Feb 15 '23 10:02

OnaBai