Prechádzať zdrojové kódy

Strip unnecessary column header data on export

ttreasure 4 mesiacov pred
rodič
commit
3abc602e48
1 zmenil súbory, kde vykonal 24 pridanie a 0 odobranie
  1. 24 0
      resources/js/reports.js

+ 24 - 0
resources/js/reports.js

@@ -28,6 +28,30 @@ function initializeDataTable() {
     var dataTablesButtonsConfig = JSON.parse(document.getElementById('datatable-config').dataset.datatableButtonsConfig);
     var dataTablesColumnDefsConfig = JSON.parse(document.getElementById('datatable-config').dataset.datatableColumnDefsConfig);
 
+    //Strip out HTML from headers when exporting
+    dataTablesButtonsConfig.forEach(function(buttonConfig){
+        buttonConfig.exportOptions = buttonConfig.exportOptions || {};
+        for(let key in buttonConfig)
+        {
+            if(key === "exportOptions")
+            {
+                console.log('Export Check');
+                buttonConfig.exportOptions.format = {
+                    header: function (data){
+                        const tempDiv = document.createElement('div');
+                        tempDiv.innerHTML = data;
+
+                        // Remove all <select> elements
+                        tempDiv.querySelectorAll('select').forEach(el => el.remove());
+
+                        return tempDiv.textContent.trim().replace(/\s+/g, ' ');
+
+                    }
+                }
+            }
+        }
+    })
+
 
     //Set up any action columns
     function doActionButton(url, id)