Skip to content

Commit

Permalink
d645c0a4fbbb3383f54962501b3245bc5fb6801f Fix: Header and footer data …
Browse files Browse the repository at this point in the history
…from `-api buttons.exportData()` was not being passed through the formatting options

https://datatables.net/forums/discussion/78366/

Sync to source repo @d645c0a4fbbb3383f54962501b3245bc5fb6801f
  • Loading branch information
dtbuild committed Mar 4, 2024
1 parent 05b0aef commit d460f18
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion datatables.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
],
"src-repo": "http://github.com/DataTables/Buttons",
"last-tag": "3.0.0",
"last-sync": "1448ef49c8cfec092b563419a2edb96753ee1a67"
"last-sync": "d645c0a4fbbb3383f54962501b3245bc5fb6801f"
}
28 changes: 26 additions & 2 deletions js/dataTables.buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2693,9 +2693,15 @@ var _exportData = function (dt, inOpts) {

var data = {
header: header,
headerStructure: dt.table().header.structure(config.columns),
headerStructure: _headerFormatter(
config.format.header,
dt.table().header.structure(config.columns)
),
footer: footer,
footerStructure: dt.table().footer.structure(config.columns),
footerStructure: _headerFormatter(
config.format.footer,
dt.table().footer.structure(config.columns)
),
body: body
};

Expand All @@ -2706,6 +2712,24 @@ var _exportData = function (dt, inOpts) {
return data;
};

function _headerFormatter(formatter, struct) {
for (var i=0 ; i<struct.length ; i++) {
for (var j=0 ; j<struct[i].length ; j++) {
var item = struct[i][j];

if (item) {
item.title = formatter(
item.title,
j,
item.cell
);
}
}
}

return struct;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* DataTables interface
*/
Expand Down
2 changes: 1 addition & 1 deletion js/dataTables.buttons.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dataTables.buttons.min.mjs

Large diffs are not rendered by default.

28 changes: 26 additions & 2 deletions js/dataTables.buttons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2653,9 +2653,15 @@ var _exportData = function (dt, inOpts) {

var data = {
header: header,
headerStructure: dt.table().header.structure(config.columns),
headerStructure: _headerFormatter(
config.format.header,
dt.table().header.structure(config.columns)
),
footer: footer,
footerStructure: dt.table().footer.structure(config.columns),
footerStructure: _headerFormatter(
config.format.footer,
dt.table().footer.structure(config.columns)
),
body: body
};

Expand All @@ -2666,6 +2672,24 @@ var _exportData = function (dt, inOpts) {
return data;
};

function _headerFormatter(formatter, struct) {
for (var i=0 ; i<struct.length ; i++) {
for (var j=0 ; j<struct[i].length ; j++) {
var item = struct[i][j];

if (item) {
item.title = formatter(
item.title,
j,
item.cell
);
}
}
}

return struct;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* DataTables interface
*/
Expand Down

0 comments on commit d460f18

Please sign in to comment.