jqGrid 清除搜索条件 [英] jqGrid clear search criteria

查看:24
本文介绍了jqGrid 清除搜索条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个启用搜索的网格设置.当我运行搜索时,一切正常,我可以将好的数据返回给网格.我看到 URL 上的_search"参数设置为true",一切正常.

Currently I have a grid set up with the search enabled. When I run a search everything works fine and I can return good data back to the grid. I see that the "_search" parameter on the URL is set to "true" and all is well.

但是,当完成搜索并且数据不再相关时,我想重新加载网格以显示之前存在的数据(在初始页面加载时显示的数据).我创建了一个函数来调用trigger(reloadGrid")"方法,但这只是发送相同的数据,而_search"仍然设置为true".

However, when finished with the search and the data is no longer relevant, I would like to reload the grid to display the previous data that was there (the data displayed on the initial pageload). I made a function to call the "trigger("reloadGrid")" method, but that just sends the same data with the "_search" still set to "true".

有没有办法清除搜索请求数据并重新加载页面加载中显示的初始数据,或者至少将_search"值设置回false"以便我可以检查它?目前显示原始数据的唯一方法是重新加载页面.

Is there a way to clear out the search request data and just reload the initial data shown on pageload or at least set the "_search" value back to "false" so I can check against it? Currently the only way to display the original data is to reload the page.

推荐答案

如果使用 jqGrid 搜索,将设置以下两件事

If you use jqGrid searching the following two things will be set

    jqGrid的
  1. search参数将被设置为true.
  2. 将修改 jqGrid 的
  3. postData 参数.postData 参数的值是一个具有某些属性的对象.如果单次搜索属性searchFieldsearchStringsearchOper 将被设置.在高级搜索的情况下,只有属性filters<postData 参数的/code> 将被设置.(属性_search也会被设置,但是来自jqGrid的另一个组件,所以对于搜索的重置并不重要.)
  1. search parameter of jqGrid will be set to true.
  2. postData parameter of jqGrid will be modified. The value of the postData parameter is a object which has some properties. In case of single searching the properties searchField, searchString and searchOper will be set. In case of advanced searching only the property filters of the postData parameter will be set. (The property _search will be also set but from another component of jqGrid, so it is not important for the reset of searching.)

因此要重置搜索,您可以为重置搜索"按钮定义以下事件处理程序:

So to reset the searching you can define the following event handler for your "Reset Search" button:

$("#resetSearch").click(function() {
    var grid = $("#list");
    grid.jqGrid('setGridParam',{search:false});

    var postData = grid.jqGrid('getGridParam','postData');
    $.extend(postData,{filters:""});
    // for singe search you should replace the line with
    // $.extend(postData,{searchField:"",searchString:"",searchOper:""});

    grid.trigger("reloadGrid",[{page:1}]);
});

您可以在以下演示中看到所有这些.在演示中,您应该首先单击导航栏的搜索"按钮并设置搜索过滤器.然后你可以点击重置搜索"按钮并重置它.

You can see all this live in the following demo. In the demo you should first click on the "Search" button of the navigation bar and set a search filter. Then you can click on the "Reset Search" button and reset it.

这篇关于jqGrid 清除搜索条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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