【问题标题】:Jqgrid dynamic filter with url data source带有url数据源的jqgrid动态过滤器
【发布时间】:2019-04-25 20:28:26
【问题描述】:

我有一个 Jqgrid 如下:

 jQuery("#jQGridDemo").jqGrid({
            url: 'http://localhost:58404/JQGridHandler.ashx',
            colNames: ['Property ID', 'Property Ref', 'Short Address', 'Scheme Code', 'Scheme Name', 'Property Type', 'Tenure Type', 'Status', 'Management Cost','Rent Charge Month','SC Charge Month'],
            colModel: [
                        { name: 'PropertyID', index: 'PropertyID', width: 70, align: "left", stype: 'text', sortable: true},
                        {name: 'PropertyType',width: 80},
                        { name: 'TenureType', index: 'TenureType', width: 80, align: "center",  sortable: true },
                        { name: 'Status', index: 'Status', width: 75,  align: "center", sortable: true },
            ],

网格工作并使用从 URL 返回的 Json 进行填充。 但是,我正在尝试在 PropertyType 列上实现一个动态填充的下拉过滤器,并且一直在这里查看 Oleg 的答案:How to add dynamic filter drop down using Jqgrid?

因此我添加了一个“beforeProcessing”功能:

 beforeProcessing: function (data) {
                var propertyMap = {}, propertyValues = ":All", rows = data.rows, i, symbol;
                for (i = 0; i < rows.length; i++) {
                    symbol = rows[i].Symbol;
                    if (!propertyMap.hasOwnProperty(symbol)) {
                        propertyMap[symbol] = 1;
                        propertyValues += ";" + symbol + ":" + symbol;
                    }
                }
                $(this).jqGrid("setColProp", 'PropertyType', {
                    stype: "select",
                    searchoptions: {
                        value: propertyValues
                    }
                }).jqGrid('destroyFilterToolbar')
                    .jqGrid('filterToolbar', {
                        stringResult: true,
                        searchOnEnter: false,
                        defaultSearch: "cn"
                    });
            },

我的问题是,如何将URL返回的数据传递给“beforeProcessing:函数(数据)” -

任何帮助将不胜感激。

【问题讨论】:

  • 已经通过了。不确定我是否理解。在将数据插入网格之前,将来自服务器的数据传递给该事件。关于此事件,不同的 jqGrid 版本也存在一些差异 - 实际上使用了哪个版本的 jqGrid - Guriddo jqGrid、free-jqGrid 或 jqGrid
  • 我使用的是 4.5.1 版本。调试器告诉我 rows 为空。所以我假设数据在插入网格之前没有被传递给函数。
  • 你的数据类型是什么?如果数据类型是本地的,则不会在 4.5 版中传递。对于此版本,仅当数据类型为 json 或 xml 时才传递数据。该问题在 Guriddo jqGrid 版本中不存在。
  • 我的数据类型是 Json。
  • 尝试 console.log 数据。根据 jsonReader , data.rows 属性可能不存在。就在 rows = data.rows 之前。仅制作数据的 console.log

标签: filter drop-down-menu jqgrid


【解决方案1】:

如果您的数据没有 rows 属性,您可以像这样修改初始代码:

 beforeProcessing: function (data) {
                var propertyMap = {}, propertyValues = ":All", rows = data, i, symbol;
                for (i = 0; i < rows.length; i++) {
                    symbol = rows[i].Symbol;
                    if (!propertyMap.hasOwnProperty(symbol)) {
                        propertyMap[symbol] = 1;
                        propertyValues += ";" + symbol + ":" + symbol;
                    }
                }
....

唯一与原始代码不同的是替换

rows = data.rows

行 = 数据,

【讨论】:

  • 谢谢。这一变化使一切变得不同。我是 Jqgrid 的新手。你会推荐我使用哪个版本?
  • 这取决于您的期望。您可以使用我们的商业版 Guriddo jqGrid 保证支持和开发,或者您可以使用开源 fork free-jqGrid,它只得到 Oleg 的支持,没有未来的开发
猜你喜欢
  • 1970-01-01
  • 2016-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-14
  • 1970-01-01
  • 1970-01-01
  • 2013-03-07
相关资源
最近更新 更多