Forum


11:29

27/04/2010

Hello,
I am using jqGridImport and jqGridExport to load the configuration of a grid and to save it to the server after the user has modified the hidden and showed columns with a column chooser.
The loading works just great. The column chooser too thanks to Tony's help!
However, I have a problem with the export.
I use this code to import the grid configuration, add a navigator and a columnchooser on it, then to export the configuration after an action has been performed in a column chooser:
imptype: 'json',
impurl: "/handlers/UsersJqGridImport.ashx",
mtype: 'POST',
jsonGrid: { config: 'Settings' },
importComplete: function() {
$('#grid_users').jqGrid('navGrid', '#pager_users', {
edit: false,
add: false,
del: false,
search: false,
refresh:false
}).jqGrid('navButtonAdd', '#pager_users', {
caption: 'Colonnes',
position: 'last',
title: 'Show/Hide/Reorder columns',
onClickButton: function() {
$('#grid_users').jqGrid('columnChooser', {
done: function(perm) {
if (perm) {
var gridWidth = this.jqGrid('getGridParam', 'width');
this.jqGrid('setGridWidth', gridWidth);
this.jqGrid('remapColumns', perm, true);
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: "/handlers/UsersJqGridExport.ashx",
data: {exportdata: $('#grid_users').jqGridExport({
exptype: 'jsonstring',
root: 'Settings'
})}
});
}
}
});
}
});
}
});
The thing is, when I try to get the exportdata on the serverside, I only get an empty string…
When using firebug, I can see that the exportdata posted in the request header has a problem with encoding:
exportdata=%7B%22Settings%22%3A%7B%0A%09%09%22url%22%3A%22%2Fhandlers%2FAltaresJqGridLoad.ashx%22%2C………………………………………..
Does someone have an idea on how to solve this problem?
Thank you.
11:55

27/04/2010

I have try to modify my JS code like this:
imptype: 'json',
impurl: "/handlers/UsersJqGridImport.ashx",
mtype: 'POST',
jsonGrid: { config: 'Settings' },
importComplete: function() {
$('#grid_users').jqGrid('navGrid', '#pager_users', {
edit: false,
add: false,
del: false,
search: false,
refresh:false
}).jqGrid('navButtonAdd', '#pager_users', {
caption: 'Colonnes',
position: 'last',
title: 'Show/Hide/Reorder columns',
onClickButton: function() {
$('#grid_users').jqGrid('columnChooser', {
done: function(perm) {
if (perm) {
var gridWidth = this.jqGrid('getGridParam', 'width');
this.jqGrid('setGridWidth', gridWidth);
this.jqGrid('remapColumns', perm, true);
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: "/handlers/UsersJqGridExport.ashx",
data: $('#grid_users').jqGridExport({
exptype: 'jsonstring',
root: 'Settings'
})
});
}
}
});
}
});
}
});
Now with firebug I get this when looking at what is posted:
So now I don't have any encoding problem.
The thing is how can I get the JSON data on the server side?
16:40

27/04/2010

I have tried many things but nothing worked.
When I use advanced search, the different filters are passed to an url in JSON format with a post variable named "filters":
filters =
{"groupOp":"AND",
"rules":[
{"field":"invdate","op":"ge","data":"2007-10-06"},
{"field":"invdate","op":"le","data":"2007-10-20"},
{"field":"name","op":"bw","data":"Client 3"}
]
}
The json encoding of the different filters appear to be fine and don't have en encoding problem.
I can work with this jsonstring and use it on the server side without any problem.
But when I try to export the grid configuration in JSON format with the following AJAX request I get an encoding problem that prevents me from doing anything with the jsonstring in the server side:
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: "/handlers/UsersJqGridExport.ashx",
data: {exportdata: $('#grid_users').jqGridExport({
exptype: 'jsonstring',
root: 'Settings'
})}
});
I get this kind of encoding:
exportdata=%7B%22Settings%22%3A%7B%0A%09%09%22url%22%3A%22%2Fhandlers%2FAltaresJqGridLoad.ashx%22%2C
Does anyone know how to send the exported configuration jsonstring with the rigth encoding?
Thanks.
17:20

27/04/2010

In fact, it appears when looking the source code of the request with firebug that the encoding is the same for the advanced search and the export jsonstring.
Both are encoding using urlencoding.
Only, for the filters, firebug can decode the jsonobject while it can't for the exportdata.
The exportdata appears to be too big for firebug.
Thus, if the filters for the search can be read on the server side, so should be the exportdata.
Is it possible that an exportdata too big prevents it from beeing transmitted entirely to the server?
12:56

Moderators
30/10/2007

Hello,
If you use get method in the ajax that send the data to the server this is quite possible,
Please use post method in the ajax request when you send data to the server.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
14:30

27/04/2010

Apparently, I don't have any double quotes in my column names.
All I know is that when I try to read the content of the exportdata on the server side, I get an empty string.
But when I look at what is posted with firebug, the exportdata is not empty but appear to be too long for firebug.
I can't figure it out.
17:12

27/04/2010

Finally!!!
I have succeeded in exporting the configuration and saving it on the server side.
The trick was:
- Be sure that there is neither a single or a double quote in a column name.
- Do not specify a POST parameter in order to pass the export data to the server but rather send the result of the jqGridExport method directly into the AJAX call data parameter.
- On the server side, read the request inputstream directly from the http context with a streamreader and convert it to a string afterwards.
Here is an exemple of the AJAX call definition:
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: "/handlers/testJqGridExport.ashx",
data: $('#grille_altares').jqGridExport(
{
exptype: 'jsonstring',
root: 'Settings'
}
)
});
I hope this will help some people.
Thanks!
Most Users Ever Online: 715
Currently Online:
38 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66