getnamingo-registry/cp/resources/views/partials/js-reports.twig
2024-01-09 08:10:23 +02:00

81 lines
No EOL
3.6 KiB
Twig

<script src="/assets/js/tabulator.min.js" defer></script>
<script src="/assets/js/tabler.min.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.6.0/jspdf.plugin.autotable.min.js"></script>
<script>
var table;
document.addEventListener("DOMContentLoaded", function(){
table = new Tabulator("#reportTable", {
ajaxURL:"/api/records/statistics", // Set the URL for your JSON data
ajaxConfig:"GET",
pagination:"local",
paginationSize:10,
ajaxResponse:function(url, params, response){
return response.records;
},
layout:"fitDataFill",
responsiveLayout: "collapse",
responsiveLayoutCollapseStartOpen:false,
resizableColumns:false,
initialSort:[
{column:"date", dir:"desc"},
],
columns:[
{formatter:"responsiveCollapse", width:30, minWidth:30, hozAlign:"center", resizable:false, headerSort:false, responsive:0},
{title:"{{ __('Date') }}", field:"date", headerSort:true, responsive:0},
{title:"{{ __('Total Domains') }}", field:"total_domains", headerSort:true, responsive:0},
{title:"{{ __('Created Domains') }}", field:"created_domains", headerSort:true, responsive:2},
{title:"{{ __('Renewed Domains') }}", field:"renewed_domains", headerSort:true, responsive:2},
{title:"{{ __('Transferred Domains') }}", field:"transfered_domains", headerSort:true, responsive:2},
{title:"{{ __('Deleted Domains') }}", field:"deleted_domains", headerSort:true, responsive:2},
{title:"{{ __('Restored Domains') }}", field:"restored_domains", headerSort:true, responsive:2, download:false}
],
placeholder:function(){
return this.getHeaderFilters().length ? "No Matching Data" : "{{ __('No Data') }}"; //set placeholder based on if there are currently any header filters
}
});
var searchInput = document.getElementById("search-input");
searchInput.addEventListener("input", function () {
var term = searchInput.value.toLowerCase();
if (term) { // Only apply the filter when there's a term to search for
table.setFilter(function (data) {
// Check if any of the fields contain the search term
return (
String(data.date).toLowerCase().includes(term) ||
data.total_domains.toString().includes(term) ||
data.created_domains.toString().includes(term) ||
data.renewed_domains.toString().includes(term) ||
data.transfered_domains.toString().includes(term) ||
data.deleted_domains.toString().includes(term) ||
data.restored_domains.toString().includes(term)
);
});
} else {
table.clearFilter(); // Clear the filter when the search box is emptied
}
});
});
function downloadCSV() {
table.download("csv", "data.csv");
}
function downloadJSON() {
table.download("json", "data.json");
}
function downloadXLSX() {
table.download("xlsx", "data.xlsx", {sheetName:"My Reports"});
}
function downloadPDF() {
table.download("pdf", "data.pdf", {
orientation:"portrait",
title:"My Reports",
jsPDF:{unit:"mm", format:"a4", orientation:"p"}
});
}
</script>