【问题标题】:How to create two footer rows in jqgrid如何在 jqgrid 中创建两个页脚行
【发布时间】:2012-11-21 18:16:15
【问题描述】:

我正在使用 ASP.NET WEB API 开发 jqgrid。

我想在 jqgrid 的页脚中添加两行。

所以在网上进行了一些搜索,将我带到了这个链接(2010 年),上面写着“不可能”,我在想,因为答案是 2010 年,现在可能是一些事情/可能已经做出了一些解决方法有可能。

我想在页脚中显示什么?

我想显示两行

  • 当前页面预设的数据总数
  • 所有页面中的数据总计

我能够传递数据并读取数据,问题是如何使用这些数据并在 jqgrid 中创建两个页脚行。

有什么想法吗?

【问题讨论】:

标签: asp.net-mvc jqgrid asp.net-mvc-4 asp.net-web-api


【解决方案1】:

我发现这个问题很有趣,所以我创建了the demo,它演示了两行页脚的可能实现:

主要思想是在已经存在标准页脚的表格中添加第二行。为了消除 jqGrid 代码的其他部分可能出现的问题,我将自定义行中的 footrow 类名替换为 myfootrow。为了使第二个页脚的 CSS 设置与原始图腾相同,我包含了来自 ui.jqgrid.css.ui-jqgrid tr.footrow td 的副本,并具有与 .ui-jqgrid tr.myfootrow td 相同的定义:

.ui-jqgrid tr.myfootrow td {
    font-weight: bold;
    overflow: hidden;
    white-space:nowrap;
    height: 21px;
    padding: 0 2px 0 2px;
    border-top-width: 1px;
    border-top-color: inherit;
    border-top-style: solid;
}

您将在下面找到完整的代码

footerrow: true,
loadComplete: function () {
    var $this = $(this),
        sum = $this.jqGrid("getCol", "amount", false, "sum"),
        $footerRow = $(this.grid.sDiv).find("tr.footrow"),
        localData = $this.jqGrid("getGridParam", "data"),
        totalRows = localData.length,
        totalSum = 0,
        $newFooterRow,
        i;

    $newFooterRow = $(this.grid.sDiv).find("tr.myfootrow");
    if ($newFooterRow.length === 0) {
        // add second row of the footer if it's not exist
        $newFooterRow = $footerRow.clone();
        $newFooterRow.removeClass("footrow")
            .addClass("myfootrow ui-widget-content");
        $newFooterRow.children("td").each(function () {
            this.style.width = ""; // remove width from inline CSS
        });
        $newFooterRow.insertAfter($footerRow);
    }
    $this.jqGrid("footerData", "set", {invdate: "Total (page):", amount: sum});

    // calculate the value for the second footer row
    for (i = 0; i < totalRows; i++) {
        totalSum += parseInt(localData[i].amount, 10);
    }
    $newFooterRow.find(">td[aria-describedby=" + this.id + "_invdate]")
        .text("Grand Total:");
    $newFooterRow.find(">td[aria-describedby=" + this.id + "_amount]")
        .text($.fmatter.util.NumberFormat(totalSum, $.jgrid.formatter.number));
}

在代码中,我在页脚的invdateamount 列中设置了附加信息。

【讨论】:

  • 不错的答案@Oleg,但有点晚了..我已经创建了一个(肮脏的)解决方法。我只创建一个页脚,每个单元格都有两个由 标签包围的值,然后使用一些 CSS 来获得两个页脚行的视觉效果。我正在接受这个答案,并会看看我是否有时间将我的代码更改为此。这个答案只能来自你 Oleg,我已经阅读了你发布的所有 jqgrid 答案。我也想感谢您的所有回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-21
  • 1970-01-01
  • 1970-01-01
  • 2011-05-31
  • 2011-12-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多