Getting error DataTables warning: table id=dataxxx - Cannot reinitialise DataTable.
Getting error DataTables warning: table id=dataxxx - Cannot reinitialise DataTable.
deep007
Posts: 17Questions: 2Answers: 0
I have tried to find many ways.Also I am looking for solution since last week. So finally decided to ask here may be somebody can help me Where I am doing wrong..
So Code is like this..
When User change the value of drop down on that time I have put on change function.So ajax code is like this
[CODE]
<script type="text/javascript">
function OnselectionChangge(table_te){
//alert(table_te);
$.ajax({
type: 'POST',
url: 'changeTeam2.php',
data: 'emp_teX='+table_te,
success: function(outdata){
alert(outdata);
$('#dataxxx').DataTable({
"ajax": 'tabdata.json',
"dataSrc": "data",
"bRetrieve": 'true',
aoColumns": [
{ "ID": "ID" },
{ "ca_nm": "Candidate" },
{ "ma_nm": "Manager" }
]
});
}
});
}
</script>
[/CODE]
And here is tabdata.json file which have the data like this:
[DATA]
{"data":[{"ID":"1","ca_nm":"Candidate1 test","ma_nm":"Deep Bhatt"},{"ID":"2","ca_nm":"Candidate2 test","ma_nm":"Deep Bhatt"},{"ID":"3","ca_nm":"Candidate3 test","ma_nm":"Deep Bhatt"}]}
[/DATA]
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi deep007,
When you call DataTables with options (
{}
), as you are on line 12, that initialises the table, and as the error says, this can only be done once. The problem is that you're re-initialising the table every time the change occurs.The fix is to either move the initialisation out of the change function, or to keep a flag so that you know if it's been initialised already.
Cheers,
Colin
Hey Colin,
Thanks for response.I got the problem but I have to keep that code insde onchage function only as whenever the select(drop down) option get change it take new value from tabdata.json and print it into datatable..
Can you please help me with any code or edit my code to fix this problem?
Or give me any reference link for this ?
Hi again,
A simple fix, on line 12 would be to test to see if the table has been initialised:
Hey colin,
Thanks for the response.
Did the change like you suggest but still it's not work.
Hey, when you say "still it's not work", do you mean that you get the re-initialisation error as you did before? If so, I'd search your code for other places where you're initialising the table and add that check we did earlier.
C
hey,
No now I am not getting a single error..but still not able to retrieve that data into datatable. Thanks colin.
OK, without seeing the code it's hard to know what to suggest, but the table may just need a draw. So, on that
if
statement we added yesterday, if the table is initialised (it needs anelse
on line 28), try adding the line:I don't understand why you are initialising the DataTable inside your Ajax success handler. There doesn't appear to be anything in the success handler that needs to be there rather than somewhere else.
We'd really need a link to a test page showing the issue to fully understand the problem. As Colin suggests, we are missing something at the moment and its difficult to know what without seeing the full thing.
Allan
Hey allan,colin
Thank you for response.
Ok let me explain....
I am trying to access a database using a on dropdown on-change function. Then, trying to store that data into one .json file. I want to retrieve that data into a DataTable without refreshing the current page. Right now, When I change the value of dropdown by selecting one option from it this ajax function take that variable to other page the I am passing that variable to the query using and getting the desired result and storing that output data into tabdata.json file. Now What I want is, I want to set that json file data into datatable. Every time the value of dropdown get change datatable's data must get populate according to it.
Issue:not able to store json file's data into the DataTable.
here is the Sample data Which get stored into json file.(tabdata.json)
Here is the code from which the data is stored into the json file.(file: passing.php)
This is the ajax function:(Datatablee.php)
Here is the code of the drop down,(Datatablee.php)
hey colin..
perhaps I got one thing but it doesn't seems right to do..
if i call this in ajax ** location.reload(true);** that thing work as I want..
Create your DataTable just once (outside of your Ajax handler) and use
clear()
and thenrows.add()
to add in the new data which you would retrieve via Ajax. That way the same table gets reused, you just load it up with different data as needed.Allan
Hey Allan,
Thank you for your response. I have initialize the table in this way..
Can you Please show me where should I call clear() and rows.add()?
in above code?
Hey colin,
Thank you for your response.I tried that else part And now its giving me new error
this one.Working on it.
Yes, inside your
success
callback function (line 9 for example).Clear the table data before calling back