JQGrid分组GroupText格式和修改 [英] JQGrid Grouping GroupText formatting and modification

查看:255
本文介绍了JQGrid分组GroupText格式和修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实现分组的网格,但想扩展groupText:区域中显示的详细信息.理想情况下,我将能够获取有关该分组的数据并以组名(默认值为{0})显示在该组行中.

I have a grid that implements grouping but would like to expand on the details that display in the groupText: area. Ideally I would be able to take data about that grouping and display in that group row with the group name ({0} default value).

换句话说,我试图实现的是一种不仅显示组名,而且显示到网格的JSON提要中包含的其他数据项的方法.

In other words what I am trying to achieve is a way to display not only the group name but also some other data items contained in the JSON feed to the grid.

我的搜索似乎与任何人都可以实现的目标相去甚远,但我希望有人可以阐明扩展此设置并提供格式化该区域的方法.

My searching seems to be coming up short on anyone being able to achieve this but I'm hoping someone can shed some light on expanding this setting and providing access to formating this area.

推荐答案

我发现您的问题很有趣,但是实现起来并不简单.在答案中,我展示了如何在分组的摘要行中使用自定义格式程序.

I find your question interesting, but the implementation is not simple. In the answer I showed before how one could use custom formatter in summary rows of the grouping.

演示中,您可以看到如何实现自定义格式分组文本.该演示显示以下内容:

In the demo you can see how to implement custom formatting of the grouping text. The demo display the following:

该实现仅由自定义格式化程序的实现组成可以用于以下两个目的:格式化相应列的内容的格式,以及在按列分组的情况下格式化分组文本的格式.该代码有些棘手,但我希望所有人都能照做.该代码使用输入参数的差异来定义是调用格式化程序来格式化列内容还是格式化分组文本.

The implementation consist just from the implementation of the custom formatter which can be used for both purpose: formatting of the content of the corresponding column and formatting of the grouping text in case of grouping by the column. The code is a little tricky, but I hope that all will be able follow it. The code use the differences of the input parameters to define whether the formatter will be called to format the column content or to format the grouping text.

在使用大量行的情况下,获得诸如(test4,test7)"之类的文本的代码的一部分不是很有效,但它可以工作.

One part of the code which get the texts like "(test4,test7)" is not so effective in case of the usage of large number of rows, but it works.

下面是日期"列的格式化程序代码,通常与预定义的formatter: 'date'一起使用.我在代码部分中将原始的Date-formatter称为,但用于分组文本的代码更为复杂:

Below is the code of formatter of the "Date" column which would by typically used with the predefined formatter: 'date'. I called in the part of the code the original Date-formatter, but used for the the grouping text more sophisticated code:

formatter: function (cellval, opts, rowObject, action) {
    var fullOpts = $.extend({}, $.jgrid.formatter.date, opts),
        formattedDate = $.fmatter.util.DateFormat('Y-m-d', cellval, 'd-M-Y', fullOpts),
        groupIdPrefix = opts.gid + "ghead_",
        groupIdPrefixLength = groupIdPrefix.length,
        month = Number(cellval.split('-')[1]), // input format 'Y-m-d'
        names = [], data, i, l, item;

    // test wether opts.rowId start with opts.gid + "ghead_" and integer
    // and rowObject is the array and action is undefined.

    if (opts.rowId.substr(0, groupIdPrefixLength) === groupIdPrefix && typeof action === "undefined") {
        // custom formating of the group header
        // we just simulate some login by testing of the month > 9

        // the next code fragment is not effective, but it can be used
        // in case of not so large number of groups and the local data
        data = $(this).jqGrid("getGridParam", "data");
        for (i = 0, l = data.length; i < l; i++) {
            item = data[i];
            if (item.invdate === cellval) {
                names.push(item.name);
            }
        }

        return (month > 9 ? ('<span class="ui-icon ui-icon-alert" style="float: left;"></span>' +
            '<span style="color:tomato; margin-left: 5px;">') : "<span>") +
            formattedDate + ' (' + names.join() + ')</span>'
    }
    return formattedDate;
}

已更新:该演示的固定版本为这里.它使用$.fn.fmatter而不是当前从jqGrid方法$.fmatter.util.DateFormat中删除.

UPDATED: The fixed version of the demo is here. It uses $.fn.fmatter instead of currently removed from jqGrid method $.fmatter.util.DateFormat.

这篇关于JQGrid分组GroupText格式和修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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