Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
problem with exporting grid configuration in jsonstring format
05/05/2010
11:29
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

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! Laugh

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:

$('#grid_users').jqGridImport({
      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.

06/05/2010
10:40
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

I can't figure it out. What can be the cause for this wrong encoding? And is it really this encoding problem that disable the possibility to get this data on the server side ina  string?

06/05/2010
10:55
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

In fact this encoding is an encoding that prevents problem with unsafe characters by encoding them with % followed by the ISO-8859-1 corresponding code of the character.

The thing is I don't know if it is automatically decoded in the server side or not.

06/05/2010
11:18
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

I think is is automatically decoded on the serverside or I would'nt get an empty string.

Maybe the problem is that the decoded jsonstring contains double quotes and it is a problem to hold this quotes in a normal string.

06/05/2010
11:55
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

I have try to modify my JS code like this:

$('#grid_users').jqGridImport({
      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:

{"Settings":{

"url":"/handlers/UsersJqGridLoad.ashx",

"height":300.....

So now I don't have any encoding problem.

The thing is how can I get the JSON data on the server side?

10/05/2010
16:40
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

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:

$.ajax({
                    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.

10/05/2010
17:20
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

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/05/2010
12:56
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

12/05/2010
14:16
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

Unfortunately, I already use the POST method.

Maybe this is not a transmission problem but rather a problem with the configuration content like the column names for instance that can contain double quotes.

I am presently investigating it.

12/05/2010
14:30
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

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.

12/05/2010
17:12
Avatar
Asshiah
Member
Members
Forum Posts: 74
Member Since:
27/04/2010
sp_UserOfflineSmall Offline

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:

$.ajax({
                    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!

27/01/2013
20:11
Avatar
nj
Colombia
Member
Members
Forum Posts: 3
Member Since:
27/01/2013
sp_UserOfflineSmall Offline

Hi Asshiah,

I am trying to import some predefined grid configs from a DB. However I cannot get it working.

Would you mind sharing your ashx import handler?

thanks in advance.

Nj

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
45 Guest(s)

Currently Browsing this Page:
1 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information