Skip to content

Commit

Permalink
e4bc9e36c967a8db99affbe39d9f1144b25b6769 New: sort option for `-but…
Browse files Browse the repository at this point in the history
…ton colvis` which can be set to be `alphabetic` to have the buttons shown in the dropdown sort alphabetically.

Sync to source repo @e4bc9e36c967a8db99affbe39d9f1144b25b6769
  • Loading branch information
dtbuild committed Sep 13, 2024
1 parent 9b3cb4b commit 54b3af8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 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.1.2",
"last-sync": "4013447fd9b542203cf0e082835fa200fe558c65"
"last-sync": "e4bc9e36c967a8db99affbe39d9f1144b25b6769"
}
20 changes: 20 additions & 0 deletions js/dataTables.buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,26 @@ $.extend(Buttons.prototype, {
close();
}

// Sort buttons if defined
if (options.sort) {
var elements = $('button', content)
.map(function (idx, el) {
return {
text: $(el).text(),
el: el
};
})
.toArray();

elements.sort(function (a, b) {
return a.text.localeCompare(b.text);
});

$(content).append(elements.map(function (v) {
return v.el;
}));
}

// Try to be smart about the layout
var cnt = $('.dt-button', content).length;
var mod = '';
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.

20 changes: 20 additions & 0 deletions js/dataTables.buttons.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,26 @@ $.extend(Buttons.prototype, {
close();
}

// Sort buttons if defined
if (options.sort) {
var elements = $('button', content)
.map(function (idx, el) {
return {
text: $(el).text(),
el: el
};
})
.toArray();

elements.sort(function (a, b) {
return a.text.localeCompare(b.text);
});

$(content).append(elements.map(function (v) {
return v.el;
}));
}

// Try to be smart about the layout
var cnt = $('.dt-button', content).length;
var mod = '';
Expand Down

0 comments on commit 54b3af8

Please sign in to comment.