JQGrid动态列和搜索查询 [英] JQGrid Dynamic Column and Search Query

查看:323
本文介绍了JQGrid动态列和搜索查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下数据:

Name        Month           Expense
----------  --------------  ----------
XYZ         February         10
XYZ         March            50
KLM         March            20
ABC         April            30

按照此 SO问题中的解决方案,我已经能够创建JQGrid具有费用"值的实例以列而不是行表示.例如:

Following the solution in this SO question I have been able to create a JQGrid instance that has the "Expense" value represented in columns instead of rows. For example:

Name        Expense February     Expense March     Expense April
---------   -----------------    ---------------   --------------
XYZ         30,00                50,00             0,00
KLM         0,00                 20,00             0,00
ABC         0,00                 0,00              30,00

在我动态构建的colModel中,我对每个对象使用相同的index值 动态添加的列,因此每次搜索都会自动重定向到Expense字段.

In the colModel that I am dynamically building I am using the same index value for every dynamically added column so every search will be redirected automatically to the Expense field.

这就像一个咒语:)

不幸的是,用户在搜索对话框中没有看到要在费用"字段上进行过滤的单个列,但他有机会过滤分别称为Expense FebruaryExpense MarchExpense April的列令人困惑,因为他认为这不仅会过滤Expense属性,而且还会过滤Month属性.

Unfortunately in the search dialog the users does not see a single column to filter on the Expense field but he has the opportunity to filter for the columns called respectively Expense February, Expense March and Expense April which is a little bit confusing because he thinks that is going to filter not only for the Expense property but also for the Month property.

有什么方法可以指示jqGrid插件隐藏那些不需要的标签,而仅使用一个名为Expense的通用字段?

Is there any way to instruct the jqGrid plugin to hide those unwanted labels and using only a generic field called Expense?

非常感谢您的帮助!

这是从第一次调用返回的生成对象(它包含colNames和colModel)

This is the generated object coming back from the first call (it contains colNames and colModel)

{
   "ColNames":[
      "Name", "Expense February", "Expense March", "Expense April"
   ],
   "ColModel":[
      { "name":"Name", "index":"Name", ... },
      { "name":"Expense1", "index":"Expense", ... },
      { "name":"Expense2", "index":"Expense", ... }, 
      { "name":"Expense3", "index":"Expense", ... }
   ]
}

这也是创建网格的代码

$.ajax({
    url: 'http://server/GetColumns',
    type: "post",
    dataType: "json",
    data: JSON.stringify({ }),
    contentType: "application/json; charset=utf-8",
    async: false,
    success: function (result) {
        if (result) {
            var colM = result.ColModel;
            var colN = result.ColNames;

            grid.jqGrid('GridUnload');

            grid.jqGrid({
                url: 'http://server/GetData',
                datatype: 'json',
                mtype: 'post',
                colModel: colM,
                colNames: colN,

                [other params here]
            })
        }
    },
    error: function (xhr, ajaxOptions, thrownError) {
       [...]
    },
    complete: function () {
       [...]
    }
});

推荐答案

似乎您可以将search: false包括在所有ExpenseX列中,但列Expense1除外.在这种情况下,搜索对话框将仅包含一个费用"列以进行搜索.

It seems that you can just include search: false in all ExpenseX columns excepted the column Expense1. In the case the searching dialog will contains only one 'Expense' column for searching.

已更新:如果您使用高级搜索"对话框,则可以将

UPDATED: If you use Advanced Searching Dialog you can change the "Expense February" to "Expense" with respect of the afterRedraw callback:

afterRedraw: function () {
    $(this).find("table.group td.columns option[value=Expense1]").text("Expense");
}

演示中,我更改了标准的客户端"名称从colNames到文本"!!!我的客户名称!!!":

In the demo I change the standard "Client" name which come from colNames to the text "!!! My Client Name !!!":

演示中afterRedraw的代码更长,只是因为我使用了演示(以答案为模板).它还允许使用 Enter 来开始搜索.

The code of afterRedraw in the demo is longer only because I used the demo from the answer as template. It allows additionally use Enter to start the searching.

这篇关于JQGrid动态列和搜索查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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