jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Grid 'exportdata' to xml throws error when some properties in data are missing
Tagged: #xmlexport, Exportdata, grid
This topic contains 4 replies, has 2 voices, and was last updated by svetoslav_borislavov 2 years, 7 months ago.
-
Author
-
September 13, 2022 at 3:19 pm Grid 'exportdata' to xml throws error when some properties in data are missing #122519
Hello,
I’m having an issue when exporting grid data to XML, when there is no default value provided in the data source properties.
The issue is that injqxdata.export.js it tries to call toString of an undefined value:
“Cannot read properties of undefined (reading ‘toString’) at a.appendBodyCell (jqxdata.export.js:formatted:1404:23)
at e (jqxdata.export.js:formatted:116:23)
at k (jqxdata.export.js:formatted:73:21)
at d (jqxdata.export.js:formatted:21:13)
at l.exportTo (jqxdata.export.js:formatted:414:24)
at l.exportToFile (jqxdata.export.js:formatted:617:30)
at c.<computed>.exportdata (jqxgrid.export.js:8:9577)
at b.jqx.invoke (jqxcore.js:15:57011)
at b.jqx.jqxWidgetProxy (jqxcore.js:15:62073)
at HTMLDivElement.<anonymous> (jqxcore.js:15:67978)”In my case, the data to be displayed in the grid is fetched from a backend server that returns a data transfer object, example
{id: 1, name: “John”, address: “some random address”}.
The grid datafield source contains the following: dataFieldSource for “address”: { name: “address”, type: ‘string’ }.I have two scenarios with the same issue:
1. one property, for example “address” is not defined in the backend and the object received is {id: 1, name: “John”} -> this could be fixed by forcing the backend to send default values for properties, but I would prefer not to
2. I have some custom datafields to be shown in the grid that are configurable and for these it is impossible to send default values from backend server. -> I don’t have a fix for that and I would like to know if there is a workaround for the XML export to handle undefined properties in the data objects.Thanks!
September 14, 2022 at 11:30 am Grid 'exportdata' to xml throws error when some properties in data are missing #122521Hi,
Can you please try using exportview and give us feedback if it works?
Here is a quick example of using it: http://jsfiddle.net/ep7y3x5o/Note that you need to import two scripts:
<script type=”text/javascript” src=”https://www.jqwidgets.com/jquery-widgets-demo/scripts/jszip.min.js”></script><script type=”text/javascript” src=”https://www.jqwidgets.com/public/jqwidgets/jqxexport.js”></script>
or from the package
import ‘jqwidgets-scripts/jqwidgets/jqxexport’;Best regards,
Svetoslav BorislavovjQWidgets Team
https://www.jqwidgets.com/September 14, 2022 at 11:56 am Grid 'exportdata' to xml throws error when some properties in data are missing #122522Hi,
I have already tried with export view, but it exports the hidden columns also. Setting “exportable” false is not an option because of other reasons.
September 15, 2022 at 7:21 am Grid 'exportdata' to xml throws error when some properties in data are missing #122525Hi again,
“exportview” has the same issue for PDF exporting”
Uncaught TypeError: Cannot read properties of null (reading ‘toString’)
at DataExporter.exportToPDF (jqxexport.js:671:40)
at DataExporter.exportData (jqxexport.js:171:31)
at c.<computed>._exportData (jqxgrid.export.js:8:3211)
at c.<computed>.exportview (jqxgrid.export.js:8:3293)
at b.jqx.invoke (jqxcore.js:15:57011)
at b.jqx.jqxWidgetProxy (jqxcore.js:15:62073)
at HTMLDivElement.<anonymous> (jqxcore.js:15:67978)
at Function.each (jquery-latest.js:384:23)
at jQuery.fn.init.each (jquery-latest.js:137:17)
at b.fn.<computed> [as jqxGrid] (jqxcore.js:15:67950)September 15, 2022 at 9:23 am Grid 'exportdata' to xml throws error when some properties in data are missing #122526Hi,
Okay, then try to set the fields that are undefined to an empty string or something and then export the data.
Here is an example: http://jsfiddle.net/pgvzmbhj/1/Best regards,
Svetoslav BorislavovjQWidgets Team
https://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.