Uncaught TypeError: Cannot use 'in' operator to search for 'length' in Id
Uncaught TypeError: Cannot use 'in' operator to search for 'length' in Id
itmalan
Posts: 3Questions: 1Answers: 0
Hello All,
I am trying dynamic column header in DataTables. The below code is working in the old environment. Can any help me in fixing the above mentioned issue.
Thanks in advance.
My cade is below,
function get_details(){
var payload = {start:0,draw:1,length:25 };
$.ajax({
url: "<?php echo base_url('employee/get_users_list')?>",
type: 'POST',
dataType: "JSON",
data: payload,
"success": function(json) {
var tableHeaders;
$.each(json.columns, function(i, val){
tableHeaders += "<th>" + val + "</th>";
headers_count++;
});
$("#div_data_table").empty();
$("#div_data_table").append('<table id="data_table" class="table table-bordered table-striped" ><thead><tr>' + tableHeaders + '</tr></thead></table>');
$('#data_table').DataTable(json); **//Getting Error Here**
},
});
)
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
Answers
Can you post an example of the
json
variable?Better is to post a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
As Kevin said, it's going to be the JSON. It looks like it'll contain the user list, the data that going into the data. If so, you'll need to change:
to be something like:
Colin
Hi kthorngren and colin,
Please have a look at the response data from server.
Json output data:
I copied your code here:
https://live.datatables.net/vavivita/1/edit
Looks like you need to remove the
columns
object from the JSON data. This:is not a supported format for Datatables. Comment out
delete json.columns;
and you will see the same error.Kevin
I changed the name of the object columns. It is working now. Problem solved. Thanks a lot.