0

As per documentation of Datatables.net https://datatables.net/examples/advanced_init/length_menu.html i need to write some setting to data table implementation to my thmyeleaf template,

<script th:inline="javascript">
 $(document).ready(function() {
  $('#example').DataTable( {
     "lengthMenu": [[10, 25, 50, [[${rowTotal}]]], [10, 25, 50, "All"]]
   });
 });
</script>

But on rendering,it's giving me such error.

 org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "10, 25, 50, -1], [10, 25, 50, 'All'" (template: "customer/customerlist" - line 237, col 21)

And on reading this documentation on thymeleaf,it is being said When inlining, if the expression between [[...]] is not a valid Standard Expression, it is output without modification, including the double-brackets. https://github.com/thymeleaf/thymeleaf/issues/22.

How to i solve this problem?

2
  • so what are you passing from the server side to the thymeleaf template? I only see plain javascript. you should put that in a js file and include it in the html file Commented May 18, 2017 at 16:00
  • edited question -1 -> [[${rowTotal}]] Commented May 20, 2017 at 3:06

1 Answer 1

2

Hmm, I didn't know that was how it works in thymeleaf 2. The easiest change would just be to format it differently. Something like this:

<script th:inline="javascript">
$(document).ready(function() {
  $('#example').DataTable({
    "lengthMenu": [
      [10, 25, 50, -1],
      [10, 25, 50, "All"]
    ]
  });
});
</script>

If that doesn't suit you, you could split the datatable definition into it's own javascript block and use th:inline="none" or move it to it's own external javascript file. (Why are you using th:inline="javascript" in this case anyways?).

Sign up to request clarification or add additional context in comments.

1 Comment

Wow,It works like a charm. Thanks @Metriods I am using javascript Since i need to pass total row and message for excel,pdf plugin supported by [datatables.net/].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.