Henry Caparas
Henry Caparas

Reputation: 67

SAPUI5 DatePicker dynamic InitialFocusedDateValue on sap.ui.table

For instance I have a table which consist of Start and End dates. How could I possibly dynamically (optimize way) set the InitialFocusedDateValue so that each time the user opens a datepicker, the previous date he chose will be the Focused date.

enter image description here

I've already tried the following but none worked:

  1. Calling the navigate event to set InitialFocusedDateValue but this is being called after the pop up has rendered. So the new InitialFocusedDateValue doesn't take effect the first click.
  2. Binding > not possible since it takes Date object.
  3. Assigning Ids to the controls and calling by Id > doesn't work too.

I've thought of looping through the table and assigning to each datepicker aggregation the InitialFocusedDateValue everytime a date is chosen but obviously this is a crappy approach. Hope there's an optimal way of resolving this.

Upvotes: 2

Views: 881

Answers (1)

Ruckert Solutions
Ruckert Solutions

Reputation: 1301

If you want to set InitialFocusedDateValue for the Start Date depending on the End date of the previous row:

  • Add an onChange event to the DatePicker
  • Get the value and row index of the currently changed date.
  • Check if there is a index+1 row, if yes get the content (controls) and give InitialFocusedDateValue the value from the event.

If you need to set End Date based on start date:

  • Add an onChange event to the Start Date DatePicker
  • Get the value in event callback
  • Add assign it: event.getSource().getParent().getContent()[indexOfEndDateControl].setInitialFocusedDateValue(dateValue)

Upvotes: 1

Related Questions