var todosdata; function loadToDosData(){ document.todos.setMessage("Loading Data"); fetch("/getToDosData", { method: "GET",headers: {"X-Requested-With": "XMLHttpRequest"},}) .then(response => { let status = response.statusText; if (!response.ok) { throw "HTTP error: " + response.status + "; " + status; } else return response.json(); }) .then(data => { if (document.todos.hasRows){ document.todos.data.data.splice(0,document.todos.data.data.length); document.todos.hasRows = false; } document.todos.insert({data:data.map(item => [item.id, item.datum, item.receiver,item.amount])}); document.todos.update(true); }) .catch(err => { document.todos.setMessage(err); }); } function createDtToDos(){ document.todos = new simpleDatatables.DataTable("#todos", { searchable: true, paging: true, classes: { active: "active", disabled: "disabled", selector: "form-select", paginationList: "pagination", paginationListItem: "page-item", paginationListItemLink: "page-link", table: "table table-striped table-sm", }, data: { headings: ["","Datum","Empfänger","Betrag"], data: todosdata, }, rowRender: (row, tr, _index) => { tr.childNodes[1].attributes.onclick = `location.href='editBill/${row.cells[0].data}'`; }, columns: [ { select:0, // render: (data, _cell, _dataIndex, _cellIndex) => { return `` }, cellClass: "datatable-icon", type: "number", hidden:true, },{ select:1, type: 'date', format: 'dd.mm.yyyy', cellClass:"dt-datum", sortable: true, sort: "desc", },{ select:2, type: 'string', cellClass:"dt-receiver", },{ select:3, type: 'number', headerClass: "dt-amount", cellClass:"dt-amount", render: renderAmount } ], template: (options, dom) => `
` }); loadToDosData(); } document.addEventListener("DOMContentLoaded", function(event) { createDtToDos(); });