Skip to content

Commit

Permalink
Apply column formats to slider labels (#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikmart authored Jan 24, 2024
1 parent 65dcafc commit 2476bf7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

- Fixed a bug that caused the date picker widget from the DateTime extension to render incorrectly (thanks, @mikmart, #1116).

- Column formatting now also applies to range labels shown on filter sliders (thanks, @GitChub, @mikmart, #247).

# CHANGES IN DT VERSION 0.31

- Upgraded DataTables version to 1.13.6 (thanks, @stla, #1091).
Expand Down
17 changes: 16 additions & 1 deletion inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,23 @@ HTMLWidgets.widget({
}
r1 = t1; r2 = t2;
})();
// format with active column renderer, if defined
var colDef = data.options.columnDefs.find(function(def) {
return (def.targets === i || inArray(i, def.targets)) && 'render' in def;
});
var updateSliderText = function(v1, v2) {
$span1.text(formatDate(v1, false)); $span2.text(formatDate(v2, false));
// we only know how to use function renderers
if (colDef && typeof colDef.render === 'function') {
var restore = function(v) {
v = scaleBack(v, scale);
return type !== 'date' ? v : new Date(+v);
}
$span1.text(colDef.render(restore(v1), 'display'));
$span2.text(colDef.render(restore(v2), 'display'));
} else {
$span1.text(formatDate(v1, false));
$span2.text(formatDate(v2, false));
}
};
updateSliderText(r1, r2);
var updateSlider = function(e) {
Expand Down

0 comments on commit 2476bf7

Please sign in to comment.