jQuery UI Widgets Forums Grid Grid 'exportdata' to xml throws error when some properties in data are missing

This topic contains 4 replies, has 2 voices, and was last updated by  svetoslav_borislavov 2 months, 1 week ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author

  • georgianat
    Participant

    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!

    • This topic was modified 2 months, 1 week ago by  georgianat.

    Hi,

    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 Borislavov

    jQWidgets Team
    https://www.jqwidgets.com/


    georgianat
    Participant

    Hi,

    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.


    georgianat
    Participant

    Hi 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)

    Hi,

    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 Borislavov

    jQWidgets Team
    https://www.jqwidgets.com/

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.