This is a migrated thread and some comments may be shown as answers.

Do you have a demo of the Slider using a date range?

2 Answers 262 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Brent Hetland
Top achievements
Rank 1
Brent Hetland asked on 05 Feb 2014, 01:38 PM
Hi,

I am using version Q3 1114 2013 of your controls.

I want to use the slider for a date range, where the start and end dates vary so they have to be set at runtime.

I want to show ticks of the dates between the start and end date range, so the user will be able to see the timeline.  I am currently using SmallChange="7" and LargeChange="28" so that each small change is a week and each large change is 4 weeks.

If I understand correctly, I need to set ItemType="Item" and then add RadSliderItems to create the ticks.

Of course since I don't have a fixed date range, I will have to add RadSliderItems at runtime as well.

I have the slider working correctly until I programatically add the RadSliderItems.  If I add the RadSliderItems programatically, the RadSlider's SelectionStart and SelectionEnd are no longer set correctly.  Instead of them being set to the leftmost and rightmost dates in the range, they are both set to the far right.

My first question is:  Do you have an example of doing this?  Please don't refer me to your online demo for adding RadSliderItems.  It doesn't show how to do all of this programatically using dates.

Here is my code.  Can you tell me what I might be doing wrong, that would cause my SelectionStart and SelectionEnd to be wrong when I add my RadSliderItems?
If I comment out the code that adds the RadSliderItems, the code below that (that sets the minimum / maximum / selectionstart / selectionend) works fine and the slider works fine.

Dim firstDate As Date = Today
Dim lastDate As Date = Today

If (Not Page.IsPostBack) Then
firstDate = filteredTaskList(0).apTaskPlannedStart
lastDate = filteredTaskList(filteredTaskList.Count - 1).apTaskPlannedEnd

Do Until firstDate >= lastDate
Dim rsi As New RadSliderItem(firstDate.ToShortDateString, firstDate.ToShortDateString)
RadSlider1.Items.Add(rsi)
firstDate = firstDate.AddDays(28)
Loop
End If

If (Not Page.IsPostBack) Then
RadSlider1.MinimumValue = CInt(filteredTaskList(0).apTaskPlannedStart.ToOADate)
RadSlider1.MaximumValue = CInt(filteredTaskList(filteredTaskList.Count - 1).apTaskPlannedEnd.ToOADate)

RadSlider1.SelectionStart = CInt(filteredTaskList(0).apTaskPlannedStart.ToOADate)
RadSlider1.SelectionEnd = CInt(filteredTaskList(filteredTaskList.Count - 1).apTaskPlannedEnd.ToOADate)
Else
filteredTaskList = From tasks In filteredTaskList _
 Where tasks.apTaskPlannedStart >= Date.FromOADate(RadSlider1.SelectionStart.ToString) AndAlso tasks.apTaskPlannedEnd <= Date.FromOADate(RadSlider1.SelectionEnd.ToString) _
 Select tasks
End If

Regards,
Brent

2 Answers, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 10 Feb 2014, 11:51 AM
Hello Brent,

Please check the following demo about Items in RadSlider: http://demos.telerik.com/aspnet-ajax/slider/examples/slideritems/defaultcs.aspx. As described the properties Value, SelectionStart and SelectionEnd of a slider that uses Items represent the index in the Items collection of the currently selected slider item or items. For example, if there are four items in the slider and you want the selection to start from the first item and to end at the last one, you would set SelectionStart = 0 and SelectionEnd = 3, because these are the indices of the first and the last item.

In your case you are setting SelectionStart and SelectionEnd with values of items instead of with their indices, and the slider positions the drag handles at the end because it cannot find an item with greater index.

If you want to configure the start and the end of the selection to the start and end item, I would suggest keeping SelectionStart always to 0 and SelectionEnd to the item count minus 1 (the index of the last item).

Regards,
Slav
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Brent Hetland
Top achievements
Rank 1
answered on 11 Feb 2014, 11:51 AM
Thanks Slav, I should have caught that...  I've got it working now.
Tags
Slider
Asked by
Brent Hetland
Top achievements
Rank 1
Answers by
Slav
Telerik team
Brent Hetland
Top achievements
Rank 1
Share this question
or