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

标签 jquery html jqgrid treegrid

我有一个 jqgrid treegrid 单元格,我想在具有链接和其他 html 格式的单元格中包含内容。

这可以用 jqgrid treegrid 实现吗?我没有看到文档中提到的任何内容

最佳答案

您从 jqGrid 中了解到的大多数事情都具有简单的表格数据,对于树状网格仍然有效。因此,您可以使用自定义格式化程序或自定义属性格式化程序 (cellattr) 将 HTML 放入单元格中。如果需要,您可以将 HTML 片段放入 JSON 或 XML 输入中。

the small demo :

enter image description here

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

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

demo中使用的树状网格的代码为

$("#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"
});

哪里 '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"]}
    ]
}

关于jquery - 是否可以在 jqgrid treegrid 单元格中包含 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6507186/

相关文章:

javascript - Glyphicon 图标未出现在首页和刷新后页面上

jquery - 选择 html 元素内的文本并更改样式

javascript - 使用 TinyMCE 进行实时预览(TinyMCE 的值(value))

html - 在不同屏幕尺寸上调整文本大小的最佳做法

javascript - 为什么 onClick 事件在 html 中只工作一次?

javascript - "Uncaught TypeError: Cannot call method ' indexOf ' of undefined"选中jqgrid行时

javascript - 基于 Html5 的加载进度 HUD

html - 我可以使用 CSS 按比例缩放 div 的高度吗?

jquery - Jqgrid。从键值中找到rowId

javascript - Jquery-在 Ajax 响应上创建行并根据列值对它们进行分组?