Kendo网格根据列值在列中生成动态html?

时间:2017-09-22 04:42:09

标签: javascript kendo-ui kendo-grid

我正在使用kendo网格,我需要根据列的值生成动态HTML,该列将由另一个函数返回。我有以下代码



$("#divGenerateLogin_kendogrid").kendoGrid({
                dataSource: {
                    data: data,
                    pageSize: 10
                },
                sortable: true,
                reorderable: true,
                pageable: {
                    pageSizes: true,
                    buttonCount: 5
                },
                filterable: true,
                // selectable: true ,
                // dataBound: onDataBound,
                columns: [
                    {
                        field: "StudentName",
                        title: "Student Name",
                        type: "string"
                    },
                    {
                        field: "Class",
                        title: "Class",
                        type: "string"
                    },
                    {
                        title: "Login",
                        template: "#: LoginColHtml(IsLoginAvilable==1) #"   
                    }

                ]
            });
            
            
            
function LoginColHtml(isLoginAvilable) {

            var html = "";
            if (isLoginAvilable == true) {
                html = "<button type='button' class='btn-ressetpwd'><i class='fa fa-key'></i> reset password</button>";
            } else {
                html = "<button type='button' class='btn-generatelogin'><i class='fa fa-user'></i> generate login</button>";
            }
            // "<div>#: (IsGuardianLoginAvilable==1) #</div>";
            return html;

        }
&#13;
&#13;
&#13;

而不是在列中返回实际的html,而是以字符串形式返回。如何将实际HTML添加到列而不是字符串?

FYI enter image description here

1 个答案:

答案 0 :(得分:0)

我已尝试过这个并且有效

{
     title: "Guardian Login",
     template: "#= LoginColHtml(IsLoginAvilable==1) #"     
}