0
votes

I want to load a initialization script for the dataTables plugin in a Notes Document. In this doc I store more data like type of object, data source location, display configuration. Now I would also like to store the script to initiliaze the datatable plugin.

I have can store the value in a viewScope which is set in the beforePageLoad event on an XPage.

The content of the viewScope can be as followed:

$(document).ready(function() { var table = $('#tablePager').DataTable({ "order": [ [1, "asc"] ], responsive: true, paging: false, /*stateSave: true,*/ colReorder: { reorderCallback: function() { console.log('callback'); } }, dom: 'Bfrtip', buttons: [ 'excelHtml5', 'print' ] }); //$('#tablePager_filter input').val('');});

When I try to eval the value in the onClientLoad event I get an error:

<xp:eventHandler event="onClientLoad" submit="false">
        <xp:this.script><![CDATA[eval('#{javascript:viewScope.dataTable}')
]]></xp:this.script>

Uncaught SyntaxError: Invalid or unexpected token

Does anyone has a suggestion how to convert the string into a function?

1
Why do you put client side JS in a server side viewScope variable? You can use the xp:scriptBlock control insteadPer Henrik Lausten
the value of the field is collected in another process which is written in java. so I just stored in a viewscope for convenience I guess.Patrick Kwinten
nevertheless I tried a script block instead but I get the error: Uncaught SyntaxError: Illegal return statement. for now I tried: <xp:scriptBlock id="scriptBlock1"> <xp:this.value><![CDATA[return "#{javascript:viewScope.get("dataTable")};"]]></xp:this.value> </xp:scriptBlock>Patrick Kwinten
in the source I find: <script type="text/javascript"> return "$(document).ready(function() { var table = $('#tablePager').DataTable({ \"order\": [ [1, \"asc\"] ], responsive: true, paging: false, /*stateSave: true,*/ colReorder: { reorderCallback: function() { console.log('callback'); } }, dom: 'Bfrtip', buttons: [ 'copyHtml5', 'excelHtml5', 'print' ] }); //$('#tablePager_filter input').val('');});;" </script>Patrick Kwinten
got it working now. thanks bro'!Patrick Kwinten

1 Answers

1
votes

Why do you put client side JS in a server side viewScope variable? You can use the xp:scriptBlock control instead