javascript - is there any way to initialize details in jquery datatable? -
i have problem jquery datatable details initialization. need table opened details after page has loaded.
i have following code:
function format(d) { return d; } $(document).ready(function () { $.ajax({ type: "get", datatype: "json", url: "/shop/promotions/generatedetailstojson", //teraz w tym miejscu inicjuję dane tabel success: function (result) { setdetails(result); }, error: function () { alert("wystąpił nieoczekiwany błąd"); } }) dt = $('#table').datatable( { "aocolumndefs": [ { 'bsortable': false, 'atargets': [0, 6, 7] } ] } ); dt.on('draw', function () { $.each(detailrows, function (i, id) { $('#' + id + ' td:first-child').trigger('click'); }); }); $('#table').datatable();} var table_length = $('#table tbody tr').length; //here problem var tr = document.getelementsbyclassname("details"); (var = 0; < table_length; i++) { var row = dt.row(tr[i]); row.child(format(details[i])).show(); } ); the problem in last few lines in above code. these lines need initialize , open jquery datatables details these function not execute @ time , nothing displayed. have have tried use timeout better worked not wanted , couple of refreshing 1 no data if know solution that, please help.
you must wait ajax request complete.
for example:
$(document).ready(function () { $.ajax({ //... success: function (result) { setdetails(result); process(); } }); function process() { var table_length = $('#table tbody tr').length; var tr = document.getelementsbyclassname("details"); (var = 0; < table_length; i++) { var row = dt.row(tr[i]); row.child(format(details[i])).show(); } } });
Comments
Post a Comment