No data available in table
No data available in table
cris82mi
Posts: 6Questions: 2Answers: 0
Hi,
I'm try to fill a table dinamically with the followin code, but I get the message "No data available in table" the variable t in correctly filled, can please help me?
var t = $('#opensig').DataTable();
<% for (int u = 0; u < ticket_pos.length; u++) {%>
<%if (country_pos[u] == null) {
country_pos[u] = "";
}%>
t.row.add(['<%=ticket_pos[u]%>','<%=strategy_pos[u]%>', '<%=symb_pos[u]%>', '<%=opentime_pos[u]%>', '<%=tip_pos[u]%>', '<%=size_pos[u]%>', '<%=price_pos[u]%>', '<%=actualprice_pos[u]%>', '<%=swap_pos[u]%>', '<%=profit_pos[u]%>', '<%=type_pos[u]%>', '<%=detail_pos[u]%>','<%=exposition_pos[u]%>', '<%=dateupdate_pos[u]%>', '<%=country_pos[u]%>']).draw();
<% }%>
$(document).ready(function () {
$('#opensig').DataTable({
data: t,
AutoWidth: false,
columns: [
{title: "Order ID"},
{title: "Strategy ID"},
{title: "Symbol"},
{title: "Open Time"},
{title: "Long / Short"},
{title: "Size"},
{title: "Open Price"},
{title: "Actual Price"},
{title: "Swap"},
{title: "Profit"},
{title: "Type"},
{title: "Detail"},
{title: "Field"},
{title: "Exposition"},
{title: "Date Update"},
{title: "Country"}
],
columnDefs: [{
orderable: false,
targets: 0
}],
autoFill: false,
colReorder: false,
select: true,
dom: 'Blfrtip',
buttons: ['copy', 'csv', 'excel', 'pdf', 'print', 'colvis']
});
});
This discussion has been closed.
Answers
There are a few issues-
draw()
outside of the loop as you will take a performance hit calling it for every row added.If you can access ticket_pos as a JSON array you can use that as your data property.
Thanks
Tom
Hi Tom,
I'm trying with a JSON array but I get an error, could you please help me?
Error:
WEB_Geomap_Servlet:250 Uncaught ReferenceError: json_data1 is not defined
Could you console.log json_data1 just before the datatables initialisation.
You could try putting json_data1 into a javascript variable as it looks like it isn't at the moment.
eg
var json_data1 = <% new JSONArray( ... ); %>;
You might need to echo the JSON Array or otherwise print it out.
Thanks
Tom