When restoring JQGrid via jqGridImport search information is incorrect
Asked Answered
P

1

2

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?

Peel answered 25/3, 2011 at 6:3 Comment(0)
V
2

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

Vouvray answered 25/3, 2011 at 9:7 Comment(6)
@user541319: How you can see in my example all work, so grid[0].p.postData.filters has type string. If you has an object instead of string then you do something wrong in your code before that. You should post the code which you use. I have seen at the beginning that "filters":{"groupOp":"AND","rules": [{"field":"fname","op":"bw","data":"T"}]} which you posted is definitive wrond value. the value must be converted to JSON with JSON.stringify for example. I don't know whether it is your bug or the bug in jqGridExport/jqGridImport.Vouvray
I am not saying your solution is not right, obviously it is. Am simply unable to implement it in my code yet. I don't think that JSON.stringify will solve here as I am correctly importing the export. Let me look a little more at my code.Peel
using dump to generate a string from the object I am seeing that grid[0].p.postData.filters looks like 'groupOp' => "AND" 'rules' ... '0' ... 'field' => "fname" 'op' => "bw" 'data' => "T"Peel
Using if (typeof(grid[0].p.postData.filters.rules[0]['field']) === "string" && grid[0].p.postData.filters.rules[0]['field'].length>0) works for the test. typeof(grid[0].p.postData.filters.rules[0]['field'] is returning 'fname'.Peel
@user541319: I can't follow you. Just create a grid and use "advance searching" dialog to create a filter and then look in the postData.filters. You will see that it is string and not an object. I can only repeat that you should include the code which reproduce your problem. Either there is a bug in your code or there is a bug in code of jqGridExport/jqGridImport. The type of postData.filters must be string.Vouvray
Based on your code above the following works great. grid.searchGrid(prmSearch); if (typeof(grid[0].p.postData.filters.rules[0]['field']) === "string" && grid[0].p.postData.filters.rules[0]['field'].length>0) { var cnt=0; for(var k in grid[0].p.postData.filters){ cnt++; } cnt--; $("#fbox_"+grid[0].id).searchFilter().del(cnt); }Peel

© 2022 - 2024 — McMap. All rights reserved.