Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

jquery - jqGrid clear search criteria

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.

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".

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...