如何将复杂的搜索条件从查询字符串传递到jqgrid

如何将复杂的搜索条件从查询字符串传递到jqgrid

本文介绍了如何将复杂的搜索条件从查询字符串传递到jqgrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下代码以将过滤器传递给调用jqgrid的url. jqGrid仍显示所有行,传递的过滤器未传递到url以检索服务器形式的数据.如何强制jqGrid通过查询字符串中传递的过滤器进行过滤?

I tried code below to pass filter to url which invokes jqgrid. jqGrid still shows all rows, passed filter is not passed to url to retrieve data form server.How to force jqGrid to filter by filter passed in query string ?

window.open( '/Grid?filters=' + encodeURIComponent(
  '{"groupOp":"AND","rules":[{"field":"Name","op":"cn","data":"John"}' ));

推荐答案

您可以解析window.location.href并获取所需的所有参数.如果URL包含您需要的参数,则可以根据 decodeURIComponent 对其进行解码并使用根据需要喜欢你.

You can parse window.location.href and get all parameters which you need. If the URL contains the parameter which you need you can decode it with respect of decodeURIComponent and use like you as need.

以下代码可用于测试.它演示了如何解码filters参数.

The following code can be used for tests. It demonstrate how to decode filters parameter.

if (window.location.href.indexOf('?') < 0) {
    // the code will open the current HTML page with additional
    // parameter "filters" and reopen the same page with the parameters
    window.location = window.location.href + '?' +
        $.param({
            filters: JSON.stringify({
                groupOp: "AND",
                rules: [
                    {field: "Name", op: "cn", data: "John Smith"}
                ]
            })
        });
} else {
    // decode URL parameters and place in the as properties in the
    // object "parameters":
    var namedParameters = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'),
        parameters = {},
        nameAndValue,
        i;
    for (i = 0; i < namedParameters.length; i += 1) {
        nameAndValue = namedParameters[i].split('=');
        parameters[nameAndValue[0]] = decodeURIComponent(nameAndValue[1]);
        if (nameAndValue[0] === "filters") {
            // display the data from the "filters" parameter
            var myFilters = $.parseJSON(decodeURIComponent(nameAndValue[1]));
            alert(myFilters.rules[0].data);
        }
    }
}

这篇关于如何将复杂的搜索条件从查询字符串传递到jqgrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:32