jQuery UI Widgets › Forums › Layouts › Layout and Docking Layout › unable to convert saveLayout method returned result to string
Tagged: Angular docking layout, Converting circular structure to JSON, docking layout, jQuery docking layout, jqxDockingLayout, json, load, loadLayout, save, SaveLayout, string, stringify
This topic contains 9 replies, has 4 voices, and was last updated by NotAFan 6 years, 5 months ago.
-
Author
-
Hi All,
issue Replicate Proc
1) After Rearrage or Resize the panels.
2) get updated layout using “saveLayout” method.
3) tried to convert returned object to string.its throws ” Converting circular structure to JSON’
Hi Dinesh Kumar,
Unfortunately, the object returned by the method saveLayout cannot currently be stringified, because it contains references to jQuery objects. We will, however, consider this issue and think of ways to resolve it for a future version of jQWidgets.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar,
Thanks for your clarification.
Is there any workaround for resolve this.Hi Dinesh Kumar,
I am afraid there is no workaround on the matter.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar,
Thanks for your help.
I found below solution.
Cretits to mikermcneilfunction stringify(obj, replacer, spaces, cycleReplacer) { return JSON.stringify(obj, serializer(replacer, cycleReplacer), spaces) } function serializer(replacer, cycleReplacer) { var stack = [], keys = [] if (cycleReplacer == null) cycleReplacer = function (key, value) { if (stack[0] === value) return "[Circular ~]" return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]" } return function (key, value) { if (stack.length > 0) { var thisPos = stack.indexOf(this) ~thisPos ? stack.splice(thisPos + 1) : stack.push(this) ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key) if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value) } else stack.push(value) return replacer == null ? value : replacer.call(this, key, value) } }
Convert array to string
$("#savelayout").val(stringify($('#jqxDockingLayout').jqxDockingLayout('saveLayout')));
this is working fine with me.if you found any better solution pls post to me.Thanks Dimitar
Hi Dinesh Kumar,
Thank you for the idea.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/It is possible to use JSON.stringify if you use a censor function to strip out the properties that cause the circular reference.
i.e.
function censor(key, value) { if(key.slice(0, 1) == "_") { return undefined; } return value; } var layout = JSON.stringify($('#dockinglayout').jqxDockingLayout('saveLayout'), censor); // Generates a string representing the layout
The layout can then be restored using
$('#dockinglayout').jqxDockingLayout('loadLayout', JSON.parse(layout)); // Parses the string and restores the layout
Hello,
I try to get one of the mentioned solutions working: both throw an error if you for example rearange Document-Panel:
jqxlayout.js:7 Uncaught TypeError: c[A].appendTo is not a function
at b.(anonymous function)._createLayout (https://ff.zzz.de/jqwidgets/jqxlayout.js:7:17327)
at b.(anonymous function)._createLayout (https://ff.zzz.de/jqwidgets/jqxlayout.js:7:17435)
at b.(anonymous function)._createLayout (https://ff.zzz.de/jqwidgets/jqxlayout.js:7:17435)
at b.(anonymous function)._createLayout (https://ff.zzz.de/jqwidgets/jqxlayout.js:7:17435)
at b.(anonymous function)._createLayout (https://ff.zzz.de/jqwidgets/jqxlayout.js:7:17435)
at b.(anonymous function).render (https://ff.zzz.de/jqwidgets/jqxlayout.js:7:2123)
at b.(anonymous function).loadLayout (https://ff.zzz.de/jqwidgets/jqxlayout.js:7:3167)
at b.(anonymous function).loadLayout (https://ff.zzz.de/jqwidgets/jqxdockinglayout.js:7:804)
at Object.a.jqx.invoke (jqxcore.js:14)
at Object.a.jqx.jqxWidgetProxy (jqxcore.js:14)How should it be possible to save the layout in a database without JSON?
Please help me with a working solution.
Best Regards
DirkHello Dirk,
As previously mentioned, the object returned by the method saveLayout cannot be stringified reliably. You can try the solutions of other users (modifying jqxdockinglayout content, Problems persisting docking layout), but there is no guarantee they would work in your scenario, and, unfortunately, there is no official solution on the matter.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hello Dimitar,
this is very bad. The control is therefore useless for me.
I will write a mail to your support.with Regards
Dirk -
AuthorPosts
You must be logged in to reply to this topic.