diff --git a/NEWS.md b/NEWS.md index 04a6986e..86b22f02 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). diff --git a/inst/htmlwidgets/datatables.js b/inst/htmlwidgets/datatables.js index 62a9e682..6e7feb60 100644 --- a/inst/htmlwidgets/datatables.js +++ b/inst/htmlwidgets/datatables.js @@ -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) {