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

查看:592
本文介绍了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参数的值是一个具有某些属性的对象.如果单次搜索属性searchFieldsearchOper将被设置.在高级搜索的情况下,仅高级搜索 postData参数将被设置. (还将设置属性_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天全站免登陆