Skip to content

Commit

Permalink
Apply column formats to slider labels (rstudio#1119)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikmart authored and AhmedKhaled945 committed Feb 2, 2024
1 parent 69a69ee commit eabbade
Show file tree
Hide file tree
Showing 2 changed files with 21 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
20 changes: 19 additions & 1 deletion inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,25 @@ HTMLWidgets.widget({
}
r1 = t1; r2 = t2;
})();
$span1.text(formatDate(r1)); $span2.text(formatDate(r2));
// 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) {
// 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) {
var val = filter.val();
// turn off filter if in full range
Expand Down

0 comments on commit eabbade

Please sign in to comment.