是否可以在jqgrid treegrid单元格中包含html

leo*_*ora 2 html jquery jqgrid treegrid

我有一个jqgrid treegrid单元格,我希望内容具有链接和其他HTML格式的单元格.

这有可能与jqgrid treegrid?我没有看到文档中提到的任何内容

Ole*_*leg 7

从jqGrid知道的大多数具有简单表格数据的东西仍然对树网格有效.因此,您可以使用自定义格式化程序或自定义属性formatter(cellattr)将HTML放入单元格中.如果需要,您可以将HTML片段放在JSON或XML输入中.

看看小演示:

在此输入图像描述

唯一重要的是要理解,树网格不支持数据分页,因此您应该将rowNum参数设置为足够大的值,如10000.

我建议你检查树网格包含.你会看到隐藏列'level','parent','isLeaf','expanded','loaded''icon'作为最后的网格列.此外,您将看到所有树节点(已展开且未展开)已添加到网格中.尚未扩展的节点只是隐藏.

演示中使用的树网格的代码是

$("#tree").jqGrid({
    url: 'AdjacencyTreeWithHTML.json',
    datatype:'json',
    mtype:'GET',
    colNames: ["ID", '<span style="color:Tomato">Description</span>', "Total"],
    colModel: [
        {name:'id', index:'id', width: 1, hidden: true, key: true},
        {name:'desc', width:180, sortable:false},
        {name:'num', width:80, sortable:false, align:'center',
         cellattr: function (rowId, tv, rawObject, cm, rdata) {
            return Number(tv) <=100 ? 'style="background-color:LightGreen"' :
                                      'style="background-color:Tomato"';
        }}
    ],
    treeGridModel:'adjacency',
    height:'auto',
    rowNum: 10000,
    treeGrid: true,
    ExpandColumn:'desc',
    caption:"TreeGrid Test"
});
Run Code Online (Sandbox Code Playgroud)

其中'AdjacencyTreeWithHTML.json':

{
    "total": "1",
    "page": "1",
    "records": "2",
    "rows": [
           {"id": "1", "cell":  ["1",  "Super <b>Item</b>",     "300", "0", "",  "false", "true", "true"]},
           {"id": "2", "cell":  ["2",  "<a href='http://www.google.com'>Google</a>", "100", "1", "1", "false", "false", "true"]},
           {"id": "3", "cell":  ["3",  "Sub Item 1",     "50",  "2", "2", "true",  "true",  "true"]},
           {"id": "4", "cell":  ["4",  "Sub Item 2",     "25",  "2", "2", "false", "false", "true"]},
           {"id": "5", "cell":  ["5",  "Sub-sub Item 1", "25",  "3", "4", "true",  "true",  "true"]},
           {"id": "6", "cell":  ["6",  "Sub Item 3",     "25",  "2", "2", "true",  "true",  "true"]},
           {"id": "7", "cell":  ["7",  "<span style='background-color:LightGreen; color:Tomato'>Item 2</span>", "200", "1", "1", "false", "true", "true"]},
           {"id": "8", "cell":  ["8",  "Sub Item 1",     "100", "2", "7", "false", "false", "true"]},
           {"id": "9", "cell":  ["9",  "Sub-sub Item 1", "50",  "3", "8", "true",  "true",  "true"]},
           {"id": "10", "cell": ["10", "Sub-sub Item 2", "50",  "3", "8", "true",  "true",  "true"]},
           {"id": "11", "cell": ["11", "Sub Item 2",     "100", "2", "7", "true",  "true",  "true"]}
    ]
}
Run Code Online (Sandbox Code Playgroud)

  • @AaA:我试图保持与以前版本的jqGrid的最小兼容性,但我必须进行最小的更改.例如,从4.15.0开始,我更改了"autoencode"选项的默认值,以防止默认情况下阻止跨站点划分(XSS)*.我想你可以通过在jqGrid中添加`autoencode:false`选项来解决你的问题.要发短信XSS错误,我建议您在编辑数据时在网格中输入`<script> alert("hi!")</ script>`. (2认同)