search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Keep expanded/Collapsed state after a postback Daypilot Gantt

Asked by pie_z
6 years ago.

Hi,
I'm looking for a way to keep the Expanded/Collapsed state after a postback.

I know that in the event "DayPilotGantt_BeforeTaskRender" I can set the Expanded property, but I have no idea how to memorize the expanded state and set again after a postback.

Could you give me a suggestion?

Thank you

Answer posted by Dan Letecky [DayPilot]
6 years ago.

If you set StoreTasksInViewState="true" the current state of the whole task hierarchy will be saved in the ViewState and it will be available on the server side during PostBacks.

Comment posted by pie_z
6 years ago.

Thank you.
I've made some tests and it doesn't work if in the PostBack event I call the databind().
How can I solve this?

I'm sorry but I have no ideas...

Comment posted by pie_z
6 years ago.

I set this two property in the PageLoad event:
DayPilotGantt.EnableViewState = True
DayPilotGantt.StoreTasksInViewState = True

Could you show me how to access to the expanded property from the BeforeTaskRender event? You wrote that it will be available on server side during PostBacks, could you show me how to access it?

Comment posted by Dan Letecky [DayPilot]
6 years ago.

The state of each node is available in Tasks property. Check the Expanded value of each node before calling DataBind(). You can also save the state in a special Dictionary (key = id, value = Expanded) and re-apply it to the tree after DataBind().

Another option is to avoid "PostBack" and "CallBack" event handling - they require the data to be reloaded in the event handler. For some events (such as TaskMove) it's possible to use "Notify" mode which updates the client immediately and notifies the server using the event handler afterwards. In that case, a rebind it not required.

Comment posted by pie_z
6 years ago.

Thank you, I think the first option is the best way for me. I'm trying hard, but with no result. I wrote this routine:

Private Sub SaveExpandedState()
Dim ExpandedDictionary As New Dictionary(Of Integer, Boolean)
For Each task As Task In DayPilotGantt.Tasks
ExpandedDictionary.Add(task.Id, task.Id)
Next
Session("ExpandedDictionary") = ExpandedDictionary
End Sub

Private Sub DayPilotGantt_DataBinding(sender As Object, e As EventArgs) Handles DayPilotGantt.DataBinding
SaveExpandedState()
End Sub

But the object DayPilotGantt.Tasks is always empty. I've tried to put it everywhere, al in page load. I have no idea where to get the expanded value...
Could you give me one more suggestion please?

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.