如何在 jqgrid 中创建两个页脚行 [英] How to create two footer rows in jqgrid

查看:27
本文介绍了如何在 jqgrid 中创建两个页脚行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on jqgrid with ASP.NET WEB API.

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

I want to add two rows in the footer of jqgrid.

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

So a little search on the net brought me to this link (2010) which says "It is not possible", I am thinking as the answer is of 2010, may be by now some thing / some workaround may have been made possible for this.

我想在页脚中显示什么?

我想显示两行

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

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

I am able to pass the data and read the data, the question is how to use this data and create two footer rows in jqgrid.

有什么想法吗?

推荐答案

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

I found the question interesting, so I created the demo which demonstrates one from the possible implementation of two-rows footer:

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

The main idea is to add the second row in the table where the standard footer already exist. To eliminate possible problems with other parts of jqGrid code I replaced footrow class name in the custom row to myfootrow. To have the same CSS settings for the second footer as the original tooter has I included the copy of .ui-jqgrid tr.footrow td from ui.jqgrid.css with the same definitions for .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;
}

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

The full code you will find below

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 列中设置了附加信息.

In the code I set additional information in columns invdate and amount of the footer.

这篇关于如何在 jqgrid 中创建两个页脚行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆