【问题标题】:how to custom header jqgrid如何自定义标题jqgrid
【发布时间】:2012-12-04 11:37:50
【问题描述】:

我想像这样创建 jqGrid
我可以分体 jqGrid 我写这段代码

var data = [[1, 45, "E123", "1/1/11", "Done", 100], [2, 46, "E124", "1/12/11", "Done", 100]];

$("#grid").jqGrid({
    datatype: "local",
    height: 250,
    colNames: ["SNO", "OrderID", "Location", "Date", "Status", "Amount"],
    colModel: [{
        name: 'SNO',
        index: 'SNO',
        width: 60},
    {
        name: 'OrderID',
        index: 'OrderID',
        width: 90,
        formatter:orderFmatter},
    {
        name: 'Location',
        index: 'Location',
        hidden: true},
    {
        name: 'Date',
        index: 'Date',
        width: 80,
        formatter:dateStatusFmatter},
    {
        name: 'Status',
        index: 'Status',
        width: 80,
        hidden: true},
    {
        name: 'Amount',
        index: 'Amount',
        width: 80}
    ],
    caption: "Stack Overflow Example",
});

var names = ["SNO", "OrderID", "Location", "Date", "Status", "Amount"];
var mydata = [];
for (var i = 0; i < data.length; i++) {
    mydata[i] = {};
    for (var j = 0; j < data[i].length; j++) {
        mydata[i][names[j]] = data[i][j];
    }
}

for (var i = 0; i <= mydata.length; i++) {
    $("#grid").jqGrid('addRowData', i + 1, mydata[i]);
}

function orderFmatter( cellvalue, options, rowObject )
{
    return "<div>" + cellvalue + "</div><hr /><div>" + rowObject.Location + "</div>";
}

function dateStatusFmatter( cellvalue, options, rowObject )
{
    return "<div>" + cellvalue + "</div><hr /><div>" + rowObject.Status+ "</div>";
}

此代码创建此网格

在这个网格中,我想要像正文网格这样的分页标题

【问题讨论】:

    标签: jqgrid jqgrid-asp.net jqgrid-formatter


    【解决方案1】:

    jqGrid 支持header grouping。如果您只需要在列标题中放置多行文本,您可以以更简单的方式实现。

    colNames 中的值可以是 HTML 片段。所以你应该把你需要的代码放在colNames的相应项中,并添加额外的CSS来强制使用auto列标题的高度,而不是jqGrid默认使用的固定高度。

    The demo在最后一列的列标题中放置HTML片段

    <div style="height: auto; padding: 4px 0;">
        <span>Shipped</span><hr /><span>via</span>
    </div>
    

    并额外使用 CSS

    .ui-jqgrid .ui-jqgrid-labels .ui-th-column>div {height: auto}
    

    结果得到如下图所示的网格

    【讨论】:

    • 感谢您的帮助,但我有一个问题,当使用此解决方案时,我无法按 Via 列排序,而仅按已发货排序。我希望当用户单击按 Via 排序的 Via 列表时,以及当用户单击按运送的网格排序时。谢谢。
    • @Pouya:排序图标会放在同一个&lt;th&gt;。因此,您必须添加更多代码才能使所有工作正常进行。看看the answerthis one
    猜你喜欢
    • 1970-01-01
    • 2014-06-23
    • 1970-01-01
    • 2016-08-12
    • 2012-10-05
    • 2016-06-25
    • 2011-10-13
    • 1970-01-01
    • 2013-04-21
    相关资源
    最近更新 更多