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?
Why do you put client side JS in a server side viewScope variable? You can use the xp:scriptBlock control instead