New to Telerik UI for ASP.NET Core? Start a free 30-day trial
Reversing the Slider Labels to be Displayed from Maximum to Minimum
Environment
Product | Telerik UI for ASP.NET Core Slider |
Product Version | 2024.4.1112 |
Description
By design, the Slider values are positioned from the minimum value to the maximum value (left to right). How can I reverse the minimum and maximum values of the Slider so the maximum value is displayed on the left and the minimum on the right?
Solution
- Set the
Min()
option to -10 and theMax()
value to -1. - Set the initial value to -10.
- Update the default Tooltip template to show the absolute value (for example, 10 instead of -10).
- Update the Slider labels to show the absolute values when the page with the Slider is loaded.
Razor
@(Html.Kendo().Slider()
.Name("reversedSlider")
.Min(-10)
.Max(-1)
.LargeStep(1)
.Value(-10)
.Tooltip(x => x.Template("#= Math.abs(value)#"))
)
When you need to get the Slider's value, use its absolute value:
Html
<script>
var slider = $("#reversedSlider").data("kendoSlider");
var sliderValue = Math.abs(slider.value());
</script>
For a runnable example based on the code above, refer to the following REPL samples: