Browse Source

export table - aggiunto filename + modifica export_action per mantenere parametri

ferrari 3 tuần trước cách đây
mục cha
commit
81662f54b2
1 tập tin đã thay đổi với 32 bổ sung15 xóa
  1. 32 15
      public/assets/js/datatable_export_action.js

+ 32 - 15
public/assets/js/datatable_export_action.js

@@ -56,7 +56,7 @@ function newexportaction(e, dt, button, config, cb) {
         fills.append(
             '<fill><patternFill patternType="solid">' +
                 '<fgColor rgb="FFDDEBF7"/><bgColor indexed="64"/>' +
-                "</patternFill></fill>"
+                "</patternFill></fill>",
         );
         const fillId = $("fill", styles).length - 1;
         fills.attr("count", $("fill", styles).length); // aggiorna count
@@ -64,7 +64,7 @@ function newexportaction(e, dt, button, config, cb) {
         // --- crea FONT bold nero ---
         const fonts = $("fonts", styles);
         fonts.append(
-            '<font><b/><sz val="11"/><color rgb="FF000000"/><name val="Calibri"/></font>'
+            '<font><b/><sz val="11"/><color rgb="FF000000"/><name val="Calibri"/></font>',
         );
         const fontId = $("font", styles).length - 1;
         fonts.attr("count", $("font", styles).length); // aggiorna count
@@ -74,7 +74,7 @@ function newexportaction(e, dt, button, config, cb) {
         cellXfs.append(
             `<xf xfId="0" applyFont="1" applyFill="1" borderId="0" fontId="${fontId}" fillId="${fillId}">
                     <alignment vertical="center"/>
-                </xf>`
+                </xf>`,
         );
         const xfId = $("cellXfs xf", styles).length - 1;
         cellXfs.attr("count", $("cellXfs xf", styles).length); // aggiorna count
@@ -103,7 +103,7 @@ function newexportaction(e, dt, button, config, cb) {
             cellXfs.append(
                 `<xf xfId="0" applyAlignment="1">
                         <alignment horizontal="left" vertical="center"/>
-                    </xf>`
+                    </xf>`,
             );
             const leftXfId = $("cellXfs xf", styles).length - 1;
             cellXfs.attr("count", $("cellXfs xf", styles).length);
@@ -122,7 +122,7 @@ function newexportaction(e, dt, button, config, cb) {
                             const baseXf = xfs.eq(parseInt(sAttr, 10)).clone();
                             if (baseXf.find("alignment").length === 0) {
                                 baseXf.append(
-                                    '<alignment horizontal="left" vertical="center"/>'
+                                    '<alignment horizontal="left" vertical="center"/>',
                                 );
                             } else {
                                 baseXf
@@ -135,11 +135,11 @@ function newexportaction(e, dt, button, config, cb) {
                             const newId = $("cellXfs xf", styles).length - 1;
                             cellXfs.attr(
                                 "count",
-                                $("cellXfs xf", styles).length
+                                $("cellXfs xf", styles).length,
                             );
                             cell.attr("s", newId);
                         }
-                    }
+                    },
                 );
             });
         }
@@ -196,12 +196,17 @@ function newexportaction(e, dt, button, config, cb) {
                 dt,
                 button,
                 config,
-                cb
+                cb,
             );
         } else if (cls.includes("buttons-excel")) {
             const origCustomize = config.customize;
-            config.filename = config.title;
+            const origTitle = config.title;
+            const origFilename = config.filename;
+
+            config.filename =
+                typeof origFilename !== "undefined" ? origFilename : origTitle;
             config.title = null;
+
             config.customize = function (xlsx) {
                 if (typeof origCustomize === "function") origCustomize(xlsx);
                 customizeHeaderExcel(xlsx);
@@ -214,7 +219,9 @@ function newexportaction(e, dt, button, config, cb) {
                 : $.fn.dataTable.ext.buttons.excelFlash
             ).action.call(self, e, dt, button, config, cb);
 
-            config.customize = origCustomize; // ripristina
+            config.customize = origCustomize;
+            config.title = origTitle;
+            config.filename = origFilename;
         } else if (cls.includes("buttons-csv")) {
             ($.fn.dataTable.ext.buttons.csvHtml5.available(dt, config)
                 ? $.fn.dataTable.ext.buttons.csvHtml5
@@ -232,7 +239,7 @@ function newexportaction(e, dt, button, config, cb) {
                 dt,
                 button,
                 config,
-                cb
+                cb,
             );
         }
 
@@ -264,15 +271,23 @@ function newexportaction(e, dt, button, config, cb) {
                     dt,
                     button,
                     config,
-                    cb
+                    cb,
                 );
             } else if (cls.includes("buttons-excel")) {
                 const origCustomize = config.customize;
-                config.filename = config.title;
+                const origTitle = config.title;
+                const origFilename = config.filename;
+
+                config.filename =
+                    typeof origFilename !== "undefined"
+                        ? origFilename
+                        : origTitle;
                 config.title = null;
+
                 config.customize = function (xlsx) {
-                    if (typeof origCustomize === "function")
+                    if (typeof origCustomize === "function") {
                         origCustomize(xlsx);
+                    }
                     customizeHeaderExcel(xlsx);
                     alignLeftCells(xlsx, config);
                     forceAllCellsAsText(xlsx);
@@ -284,6 +299,8 @@ function newexportaction(e, dt, button, config, cb) {
                 ).action.call(self, e, dt, button, config, cb);
 
                 config.customize = origCustomize;
+                config.title = origTitle;
+                config.filename = origFilename;
             } else if (cls.includes("buttons-csv")) {
                 ($.fn.dataTable.ext.buttons.csvHtml5.available(dt, config)
                     ? $.fn.dataTable.ext.buttons.csvHtml5
@@ -309,7 +326,7 @@ function newexportaction(e, dt, button, config, cb) {
                     dt,
                     button,
                     config,
-                    cb
+                    cb,
                 );
             }