Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf with Datatables

I have a Thymeleaf template with a Datatable (1.10.15). I have this datatable defined in 1 of my Thymeleaf template :

<script th:inline="javascript">

$(document).ready(function() {


    $('#deviceEventTable').dataTable( {
        order: [[ 0, "desc" ]],
        select: true,
        bLengthChange: false,
        stateSave: true,
        pageLength: 20,
        initComplete: function() {
            var api = this.api();

            if (localStorage.getItem( 'DataTables_selected' )!=null && localStorage.getItem( 'DataTables_selected' ) != 'undefined') {          
                var selected = localStorage.getItem( 'DataTables_selected' ).split(',');
                var selected = '0';
                selected.forEach(function(s) {
                api.row(s).select();
                })
            }
          }
    });


    table.on('select.dt deselect.dt', function() {
          localStorage.setItem( 'DataTables_selected', table.rows( { selected: true }).toArray() )   
        })

} );

</script>

But I got this error when I init the page:

Caused by: org.xml.sax.SAXParseException; lineNumber: 214; columnNumber: 64; The entity name must immediately follow the '&' in the entity reference.
like image 427
La Carbonell Avatar asked Apr 07 '26 02:04

La Carbonell


1 Answers

Use CDATA in script

<script th:inline="javascript">
/*<![CDATA[*/   

    //Your code

/*]]>*/
</script>

Otherwise & in condition parsing as the start of an entity

like image 124
Elizaveta Avatar answered Apr 09 '26 17:04

Elizaveta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!