问题
After having exported data using jqGridExport we import using jqGridImport. First problem was that the bottom bar options did not come back so I added that code after. So code looks like:
$("#list").jqGridImport({imptype: 'jsonstring', impstring: gridSettings})
.jqGrid('navGrid','#pager', { edit: false, add: false, del: false, search: true, refresh:true },
{},{},{},{closeOnEscape: true, multipleSearch: true, closeAfterSearch: true},{});
The critical part of the gridSettings string is:
"postData":{"_search":true,
"nd":1301031279941,
"rows":20,
"page":1,
"sidx":"a.ID",
"sord":"asc",
"filters":{"groupOp":"AND","rules": [{"field":"fname","op":"bw","data":"T"}]}
}
Everything comes up fine except for the search. The one line of search from postData above is correct but there is a second search line, which I can only describe as the default search line. If I go in and remove that line from the multiple search box everything is as it should be.
So my question is first, why does multipleSearch not come back up when I restore using jqGridImport?
Second is there a way to programmatically remove the second search line?
回答1:
The behavior of the bottom bar with the navigator is correct because it is implemented not as the part of grid. So you really have to set it additionally. You can write you own export and import of the settings.
The situation with the additional last line which will be added in the searching dialog is really a small problem which can be fixed with the following code:
var grid = $("#list");
...
grid.searchGrid(prmSearch);
if (typeof(grid[0].p.postData.filters) === "string" &&
grid[0].p.postData.filters.length>0) {
$("#fbox_"+grid[0].id).searchFilter().del();
}
$("#fbox_"+grid[0].id).searchFilter().close();
You can see the corresponding demo here. It is a small modification of the demo from my another old answer.
By the way the new filter which will be used in the next version of jqGrid will not have the problem (see the demo here).
来源:https://stackoverflow.com/questions/5429100/when-restoring-jqgrid-via-jqgridimport-search-information-is-incorrect