var datatable;
var colomnspez = columns;
function createSearchData(data, type, row){
    let details = ""; 
    data.forEach(function(item){
        details += item.comment+' '+item.description+' ';
        details += new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(item.subamount);  
    }); 
    return details;
}

colomnspez.splice(3, 0, { title: "Quelle",orderable:false, data: "source",className:"dt-source" });
colomnspez.splice(6, 0, { title: "Details",orderable:false, visible:false, searchable:true, data: "details",className:"",render: createSearchData});
$(document).ready(function(){
    datatable = $('#bookings').DataTable({
        paging: false,
        searching:true,
        scrollX:false,
        info:false, 
        order: [[ 1, 'desc' ],[ 0, 'desc' ]],
        "processing": true,
        ajax: {
            type : 'POST',
            url : '/Ajax/getTabelData',
            data : function(d){
                d.datum_start = $('#datepickers').val();
                d.datum_ende = $('#datepickere').val();
                d.source = $('#source').val();
            },
            dataSrc:''},
            layout: {
                topStart: {
                    buttons: [
                        {text:'Neue Rechnung',className:'btn-sm',action: function ( e, dt, node, config ) {
                            location.href = '/newBill/';
                        }},
                        {text:'Neuer Transfer',className:'btn-sm mx-2',action: function ( e, dt, node, config ) {
                            location.href = '/newTransfer/';
                        }},
                        ]
                },
                topEnd: 'search'
            },
//            dom: '<"toolbar">frt',
        "createdRow": function ( row, data, index ) {
            if(data.validate == "t"){
               $(row).addClass('text-bg-warning');
            }
        },
        columns: colomnspez,
    });

//    $("div.toolbar").html('<a class="btn-sm btn-secondary mx-2" href="/newBill" role="button">Neue Rechnung</a><a class="btn-sm btn-secondary" href="/newTransfer" role="button">Neuer Transfer</a>');
    $('#bookings tbody').on('click', 'td.dt-receiver', function () {collapseDetails($(this), datatable);} );
    $('#bookings tbody').on('click', 'td.dt-datum', function () {location.href = '/editBill/'+getId($(this),datatable);});
    $('#bookings tbody').on('click', 'table.tabdet', function () {location.href = '/editBill/'+$(this).attr('data-bs-id');});
});