dandelion / dandelion-datatables

Dandelion component for DataTables
http://dandelion.github.io/components/datatables/
Other
110 stars 49 forks source link

Export param problem #215

Closed tduchateau closed 10 years ago

tduchateau commented 10 years ago

Issue by rosetears from Friday Oct 11, 2013 at 06:17 GMT


  1. ExportManager.java L217 add more ‘)’ should be exportFunc.append(");}");
  2. not support zh_CN , use $.param() serialize params, Spring MVC accept param is garbled

eg: function getExtraParams(aoData){ aoData.push({ "name" : "city", "value" : '昆明' }); } var aoData = []; $.param(getExtraParams(aoData)) output city=%E6%98%86%E6%98%8E

$.download() Build the form eee

submit form later,spring mvc accept param city is %E6%98%86%E6%98%8E not 昆明.

above is my analysis above, please give advise.

version 0.9.2

tduchateau commented 10 years ago

Comment by tduchateau from Monday Oct 14, 2013 at 17:49 GMT

Crap! Thanks for your feedback @rosetears! It will be fixed in the next release!

Regards, Thibault

tduchateau commented 10 years ago

Comment by dcervera from Tuesday Oct 15, 2013 at 15:36 GMT

Hi @rosetears,

You can void the first problem customizing the export link in order to use the HTTP POST method instead of GET (used by default). To do it, you have to use the parameter "method" as follows (using JSP, I don't test it using Thymeleaf):

<datatables:export type="csv" method="post" />

Check http://dandelion.github.io/datatables/tutorials/export/customizing-export-links.html to see some examples using Thymeleaf.

Obviously this is just a workaround, it doesn't solve the main problem, but maybe it can help you.

Regards, David

tduchateau commented 10 years ago

Comment by tduchateau from Tuesday Oct 15, 2013 at 21:00 GMT

Thx @dcervera :-)

1) All the ugly code will be refactored with the #175. 2) If I understand well, it looks like an encoding issue. I'll investigate on this issue as soon as I can.

tduchateau commented 10 years ago

Comment by dcervera from Monday Dec 30, 2013 at 17:19 GMT

To solve both problems:

ExportManager.java - L215 to L217 doesn't decode parameters, should use "decodeURIComponent" and replace '+' symbol by spaces, as follows (and, at the same time, fixes the first problem :smile: ):

exportFunc.append("' + decodeURIComponent(($.param(");
exportFunc.append(params.toString());
exportFunc.append(")).replace(/\\+/g,' '));}");

And do the same for L251 to L253 (POST method):

exportFunc.append("',decodeURIComponent(($.param(");
exportFunc.append(params.toString());
exportFunc.append(")).replace(/\\+/g,' ')),'");

Currently I haven't time to do a pull request... but, anyway, here is the solution :+1:

Regards, David

tduchateau commented 10 years ago

Comment by tduchateau from Monday Dec 30, 2013 at 23:04 GMT

Hi David,

Thanks! :-) Indeed, the decodeURIComponent trick should fix the issue pointed by @rosetears. However, why the "replace +"?

Regards, Thibault

tduchateau commented 10 years ago

Comment by dcervera from Tuesday Dec 31, 2013 at 08:38 GMT

The JQuery method $.param() (http://api.jquery.com/jquery.param/) serializes the parameters. If one of them has spaces, they are replaced by plus symbol when it serializes the parameter. We have to "revert" this before decode parameters.

tduchateau commented 10 years ago

Comment by tduchateau from Tuesday Dec 31, 2013 at 14:01 GMT

I had missed that! Thanks! It should be fixed shortly.