how to config dynamic footer

how to config dynamic footer

GM_LinGM_Lin Posts: 4Questions: 3Answers: 0

html:

my js is:

var table=$('#sls_app_list').DataTable({
ajax: {
url: './ajax/' + NOW_PAGE + "_ajax.php",
data:function( d ) {
d.oper= "init";
d.year= $("#year").val();
},
error:handleAjaxError
},
"columns": [
{"data": "year_id", "title": "year"},
{"data": "year_name", "title": "name"}
]
});

and i wish use drop box list by column,so i find this code:

footerCallback: function () {
this.api().columns().every(function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo($(column.footer()).empty())
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val());
column.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
}

how can show footer in this datatable?

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Is there a tfoot tag in your HTML?

  • GM_LinGM_Lin Posts: 4Questions: 3Answers: 0
    edited June 2017

    haha I forgot it....

    my html :

                        〈table id="sls_app_list" class="display" cellspacing="0" width="100%"〉
    
                        〈/table〉
    

    and i try to add
    〈table id="sls_app_list" class="display" cellspacing="0" width="100%"〉
    〈tfoot〉〈/tfoot〉
    〈/table〉

    it's havnt show the foot...

  • allanallan Posts: 63,893Questions: 1Answers: 10,531 Site admin
    Answer ✓

    DataTables itself will not dynamically add footer cells. You'd need to do it using jQuery (or DOM methods) before you initialise the table.

    Allan

This discussion has been closed.