javascript - Kendo 网格列中的格式化 HTML 数据

标签 javascript jquery kendo-ui kendo-grid

您好,我使用以下代码在 jquery 中创建了一个 Kendo Grid:

剑道网格:

$('#divFolderNotes').kendoGrid({
        dataSource: data
        batch: true,
        columns: [
               { field: "Text", title: "Note Text" },
               { field: "CreatedByDisplayName", width: '190px', title: "Created By" },
               { field: "CreatedDateTime", width: '190px', title: "Created Datetime" },
                 ],
        scrollable: true,
        sortable: true,
        reorderable: true,
        resizable: true,
        height: 250,
        selectable: "row",
        autoSync: true,
        editable: true,// "inline",
        navigatable: true,
        columnMenu: true,
        pageable: {
            refresh: true,
            pageSizes: true,
            buttonCount: 5
        },
    })

问题:

第一列Note Text 的值将包含 HTML 格式的数据。

下面是一个更好的主意的例子:

现在数据显示为:

First Name : Nitin <br/> Second Name : Rawat

但我希望数据显示为:

First Name : Nitin
Second Name : Rawat 

此外,注释文本列将通过内联编辑进行编辑,因此在编辑模式下我也希望数据显示为:

First Name : Nitin
Second Name : Rawat 

我们将不胜感激任何帮助。

最佳答案

设置encoded将该列的属性设置为 false 以禁用自动 HTML 编码。

来自doc page :

If set to true the column value will be HTML-encoded before it is displayed. If set to false the column value will be displayed as is. By default the column value is HTML-encoded.

更改代码:

$('#divFolderNotes').kendoGrid({
        dataSource: data
        batch: true,
        columns: [
               { field: "Text", title: "Note Text", encoded: false },  #<------ Edit Here
               { field: "CreatedByDisplayName", width: '190px', title: "Created By" },
               { field: "CreatedDateTime", width: '190px', title: "Created Datetime" },
                 ],
        scrollable: true,
        sortable: true,
        reorderable: true,
        resizable: true,
        height: 250,
        selectable: "row",
        autoSync: true,
        editable: true,// "inline",
        navigatable: true,
        columnMenu: true,
        pageable: {
            refresh: true,
            pageSizes: true,
            buttonCount: 5
        },
    })

编辑: 由于在编辑时应保留换行符,也许您应该只替换 <br />带有换行符的标签。这样它将显示为表单字段中的实际换行符。这是一个例子:jQuery javascript regex Replace <br> with \n

当用户最初提交数据时这样做可能会更好,但是,如果这不是一个选项,您可以在显示数据时用 JS 替换它。

关于javascript - Kendo 网格列中的格式化 HTML 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22529853/

相关文章:

javascript - 如何使用bind传递对next()的引用?

javascript - 我为一只鸟的 Gif 代码编写了一个代码,让它飞过屏幕,但该图像不可见,即使它位于同一文件夹中

javascript - 使用 JavaScript/jQuery 替换链接中的 URL 参数值?

JavaScript 获取 GMT+0 日期?

javascript - 如何从 Kendo 网格中的 columnMenu 列表中删除一列

javascript - 尝试使用 simplexml 访问 ean 酒店列表中的名称

javascript - jQuery UI-Resizable 添加不需要的边距

jquery - 使用 jquery validate 插件返回远程字符串

kendo-ui - 如何将表列字段合并到剑道网格中的单列

kendo-ui - 我如何检查节点是否在 Kendo treeView 中展开