Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  89] [ 5]  / answers: 1 / hits: 31813  / 7 Years ago, mon, april 10, 2017, 12:00:00

I spend so much time and can not udnerstand why datatables can not refresh my table, i am getting already crazy with this datatables



my code is below, i spent weeks on it but is impossible to get it to work and i use ajax.reload



DataTablesDraw = (selector, order, pages, file, sort, column, template, data_set) ->
$(selector).DataTable
'pageLength': pages
'ordering': sort
'destroy' : true,
'paging': true
'responsive': true
'searching': false
'info': false
'lengthChange': true
'autoWidth': false
'select': true
'dom': 'Bfrtip',

'buttons': [
{
'extend': 'excelHtml5',
'title': file + new Date()
},
'copyHtml5'
],
'order': [ [ column, 'desc' ] ],
'language': {
buttons: {
copyTitle: i18n[lang]['id[9]'],
copySuccess: {
_: i18n[lang]['id[10]'] + ' %d ' + i18n[lang]['id[11]'],
1: i18n[lang]['id[12]']
}
}
}
'ajax': '/settings/ranges/ranges.txt',
dataSrc: data,
'drawCallback': (settings) ->

$('.dataTables_paginate > span').remove()
excel = $('#DataTables_Table_' + order + '_wrapper .buttons-excel').detach()
copy = $('#DataTables_Table_' + order + '_wrapper .buttons-copy').detach()

if not $('#DataTables_Table_' + order + '_wrapper thead.tfoot').length
$(this).append '<thead class=tfoot>' +
'<tr>' +
'<th colspan=10>' +
'<div class=export>' +
'<div class=buttons></div>' +
'</div>' +
'<div class=paginator></div>' +
'</th>' +
'</tr>' +
'</thead>'

paginator = $('#DataTables_Table_' + order + '_paginate').detach()
$('#DataTables_Table_' + order + '_wrapper thead .paginator').append paginator
$('#DataTables_Table_' + order + '_wrapper thead .export .buttons').append excel, copy

if @fnPagingInfo().iTotalPages <= 1
$('#DataTables_Table_' + order + '_paginate').hide()
$('#DataTables_Table_' + order + '_info').hide()
else
$('#DataTables_Table_' + order + '_paginate').show()
$('#DataTables_Table_' + order + '_info').show()

return

'columns': template
return


calling



table= DataTablesDraw '.__ranges__', 0, 25, 'Current Ranges ', true, 5, CurrentRangesTemplate, ranges #selector, order, pages, file name, sorting
table.ajax.reload()


the table is getting the data from the file everything is fine, just ajax.reload() cant fix to work



data



{data: [{status: 1, environment: demo, currency: EUR, range_to: 42342, date_update: 1491814286, server: server, date_create: 1491814286, platform: platform, range_from: 432423, user: {email: [email protected]}]}

More From » jquery

 Answers
87

The mistake was that u used ajax reload in this format


table.ajax.reload()


but in order to fix the mistake i jsut needed to do in this way


$('#table').DataTable().ajax.reload()


Hope this will help other, spent so much time on it on this small thing


[#58209] Friday, April 7, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keyanah

Total Points: 642
Total Questions: 93
Total Answers: 114

Location: Virgin Islands (U.S.)
Member since Tue, Jul 7, 2020
4 Years ago
;