update table inculding foortCallback
update table inculding foortCallback
Hi,
I am updating my table with $('#example').DataTable().ajax.reload(). This works for all rows, but not the footer that comes with a FooterCallback.
here is the code fo the table:
´´´
var editor_pos;
$(document).ready(function() {
editor_pos = new $.fn.dataTable.Editor( {
ajax: "../../../../../../DataTables/Editor/controllersKontura/positionen_St_INP_ofb.php",
table: "#liste_positionen",
fields: [
{ label: "INP ID", name: "INP_ID", default: "INP_ID", type: "hidden", attr: {type: 'number'}},
{ label: "Stapelname", name: "Stapelname", default: "Stapelname", type: "hidden"},
{ label: "PosNummer - muss eindeutig sein", name: "SUB_ID", attr: {type: 'number'}},
{ label: "Positiontext", name: "Positiontext"},
{ label: "Konto", name: "POS_Konto", type: 'select2', onFocus: 'focus',
"opts": {"allowClear": true, "placeholder": "(nicht definiert)"},
attr: {type: 'number'}},
{ label: "Netto", name: "Nettoposition" , default: 0 },
{ label: "Steuercode", name: "POS_Steuercode", default: "2", type: 'select2', onFocus: 'focus',
"opts": {"allowClear": true, "placeholder": "(nicht definiert)"},
attr: {type: 'number'}},
{ label: "Steuerbetrag", name: "Pos_MwSt_Betrag", default: 0 , attr: {type: 'number'}},
{ label: "MWSt %", name: "MWSt", type: "radio", options: [ 0, 5, 10, 12, 13, 20], default: "20", attr: {type: 'number'}},
],
} );
$('#liste_positionen').on('click', 'tbody td:not(:first-child, :last-child)', function() {
editor_pos.one('open', () => {
$('input', this).focus();
});
editor_pos.inline(table.cells(this.parentNode, '').nodes(), {
submitTrigger: -1,
submitHtml: '<i class="fa fa-save" style="font-size:24px;"/>'
});
});
$('#liste_positionen').on( 'click', 'tbody td.row-new', function (e) {
editor_pos.inline( table.cells(this.parentNode, '').nodes(), {
submitTrigger: -1,
submitHtml: '<i class="fa fa-play"/>'
} );
} );
var table = $('#liste_positionen').DataTable( {
dom: "<'toolbarpos'>Bfrtip",
ajax: {url: "../../../../../../DataTables/Editor/controllersKontura/positionen_St_INP_ofb.php", type: 'POST'},
fnInitComplete: function(){
$('div.toolbarpos').html('<div style="font-size: 14px; color: #365784; font-weight: bolder; padding-top: 10px;">Verbuchung Sachkonten:</div>');
},
columns: [
{ data: null, defaultContent: '', className: 'select-checkbox', orderable: false},
{ data: "SUB_ID", "width": "20px", render: $.fn.dataTable.render.number('.', ',', 0, ''), className: 'dt-body-right'},
{ data: "pos_text2", editField: "Positiontext", },
{ data: "kto_vorschlag", editField: "POS_Konto" },
{ data: "pos_netto1" , editField: "Nettoposition", render: $.fn.dataTable.render.number( '.', ',', 2, '' ), className: 'dt-body-right'},
{ data: "steuercode_vorsch", editField: "POS_Steuercode" },
{ data: "Pos_MwSt_Betrag_V", editField: "Pos_MwSt_Betrag",render: $.fn.dataTable.render.number( '.', ',', 2, '' ), className: 'dt-body-right'},
{ data: "Steuerproz_V", editField: "MWSt", render: $.fn.dataTable.render.number( '.', ',', 0, '' ), className: 'dt-body-right' },
{ data: "Brutto",render: $.fn.dataTable.render.number( '.', ',', 2, '' ), className: 'dt-body-right'},
],
responsive: false,
order: [ 1, 'asc' ],
select: { style: 'os', selector: 'td:first-child' },
"paging": false,
"info": "",
"searching": false,
buttons: [
{ extend: 'selectedSingle',
text: 'Kopieren',
editor: editor_pos,
formOptions: {
submitTrigger: -1,
submitHtml: '<i class="fa fa-save" style="font-size:24px;"/>' },
action: function( e, dt, node, config ) {
$.fn.dataTable.ext.buttons.createInline.action.call(this, e, dt, node, config);
var row = table.row({selected: true}).data();
var rowlast = table.row( ':last-child' ).data();
var fields = editor_pos.displayed();
for (var i=0 ; i<fields.length ; i++) {
editor_pos.field(fields[i]).val(row[fields[i]]);
editor_pos.field(fields[0]).val(rowlast[fields[0]]*1 + 1);
} } },
{ extend: 'create',
text: 'Neu',
editor: editor_pos,
formOptions: {
submitTrigger: -1,
submitHtml: '<i class="fa fa-save" style="font-size:24px;"/>' },
action: function( e, dt, node, config ) {
$.fn.dataTable.ext.buttons.createInline.action.call(this, e, dt, node, config);
var rowlast = table.row( ':last-child' ).data();
var fields = editor_pos.displayed();
for (var i=0 ; i<fields.length ; i++) {
editor_pos.field(fields[0]).val(rowlast[fields[0]]*1 + 1); } } },
{ extend: "edit", editor: editor_pos },
{ extend: "remove", editor: editor_pos },
],
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
totalnet = api
.column( 4 )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// console.log("net:" + __Netto_Calc__)
totalnet = totalnet-(__Netto_Calc__);
if (totalnet <= '0.01' && totalnet >= '-0.01') {totalnet = '-';}
totalbru = api
.column( 8 )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
totalbru = totalbru-(__Brutto_Calc__);
if (totalbru <= '0.01' && totalbru >= '-0.01') {totalbru = '-'}
// Update footer
var numFormat = $.fn.dataTable.render.number( '.', ',', 2, '' ).display;
$( api.column( 3 ).footer() ).html('Fehler:');
$( api.column( 4 ).footer() ).html( numFormat (totalnet) ) ;
$( api.column( 8 ).footer() ).html( numFormat (totalbru) );
}
} );
editor_pos
.on('submitSuccess', function () {
ajax_call('__plugName__', 'erneuern');
} );
editor_pos
.on('initEdit', function (e, node, data, items, type) {
editor_pos.field('Nettoposition').val(data.pos_netto1);
editor_pos.field('Pos_MwSt_Betrag').val(data.Pos_MwSt_Betrag_V);
editor_pos.field('Positiontext').val(data.pos_text1);
editor_pos.field('POS_Konto').val(data.kto_vorschlagNR);
editor_pos.field('POS_Steuercode').val(data.steuercode_vorschNr);
editor_pos.field('MWSt').val(data.Steuerproz_VNr);
});
editor_pos
.dependent('POS_Steuercode', function(val, data, callback, e ) {
if (val === '80') {
editor_pos.field('MWSt').set('0'); }
if (val === '99') {
editor_pos.field('MWSt').set('0'); }
callback(true);
});
} );
$(document).on('focus', '.select2.select2-container', function (e) {
// only open on original attempt - close focus event should not fire open
if (e.originalEvent && $(this).find(".select2-selection--single").length > 0) {
$(this).siblings('select').select2('open');
}
});
´´´
This question has an accepted answers - jump to answer
Answers
Are you saying the totals aren't updated?
Have you debugged the
footerCallback
to see what is happening? It executes on each draw event which means it should run after theajax.reload()
.Kevin
sorry, on checking again I noticed there is something else blocking the function - so this is solved.
Thanks
Max