How to delay initialization of Datatables?
How to delay initialization of Datatables?
PaoloValladolid
Posts: 35Questions: 0Answers: 0
I tried wrapping the initialization code as follows:
function initTable() {
$(document).ready(function() {
incidentReportsTable =
$('#incidentReportsTable').dataTable( {
"bProcessing": true,
"sPaginationType": "full_numbers",
"bFilter": false,
"sAjaxSource": 'myurl'
}
}
setTimeout (initTable,1000);
The idea is to make the Ajax call after the page has been loaded, to avoid this error:
java.lang.IllegalStateException: getOutputStream() has already been called for this response
However, my approach isn't working. Any ideas?
function initTable() {
$(document).ready(function() {
incidentReportsTable =
$('#incidentReportsTable').dataTable( {
"bProcessing": true,
"sPaginationType": "full_numbers",
"bFilter": false,
"sAjaxSource": 'myurl'
}
}
setTimeout (initTable,1000);
The idea is to make the Ajax call after the page has been loaded, to avoid this error:
java.lang.IllegalStateException: getOutputStream() has already been called for this response
However, my approach isn't working. Any ideas?
This discussion has been closed.
Replies
Allan
I thought that if I wrapped the call to $document.ready within another Javascript function, and then called that function from setTimeout(), that would delay the call to $document.ready.
I think the real problem was that on the server side (Java under Spring 3 MVC) the server was trying to compile JSPX code into HTML and write out the JSON at the same time. I figured out how to write out the data for the Datatables component directly to JSPX using the JSTL tags, eliminating the need for the Ajax call to get the data.
Paolo
What is the setting/code to put into my $(document).ready() so that it does not attempt to load the DOM until the page is fully rendered?
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:610)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:273)
at java.io.PrintWriter.write(PrintWriter.java:382)
I'll try a button or something that the user has to click before an Ajax call is made.
I think I have to find a way to not allow Datatables to make that getJson call right away. There's got to be a way to just trigger the call off of a button click or something.
Seems very odd the $(document).ready() isn't good enough - the DOM should be ready when that fires - unless Spring is loading other stuff via Ajax I suppose...
Allan