Have any of you ever tried to set the dataSource of a form on the fly?
This is what I am trying to do: I’d like to set the dataSource at runtime depending on the ‘tabIndex’ via a method/event. Is this possible? Is the SolutionModel the way to go?
A sample of a case:
The ‘main’ form does not have any specific ‘dataSource.’ I contains just ‘TabPanel’ elements (no relation present of course) that are used for the CRUD buttons and navigation among various forms -which have the actual back-end ‘dataSource’ tables.
A possible use for this would be to set/change the dataSource of the ‘main’ form while changing the tabIndex so that from the ‘main’ form we can make use of the File>Export option of Servoy. For example, if the tabIndex = 1, then we set the dataSource = customers. Once the dataSource is set, then I can use File>Export option of Servoy to export the customers table and its related data.
I can’t think of any other usage yet, but I am sure that some will come to my mind.
Any ideas? Thanks!
Carlos
Hi Carlos,
You can’t really change the datasource on a form. You can however create a new form on the fly using the solutionModel and set the datasource that way.
So in the end you are using different forms anyway so why not use different (designtime) forms in the first place ![Smile :)]()
ROCLASI:
So in the end you are using different forms anyway so why not use different (designtime) forms in the first place ![Smile :)]()
Because I’d miss the point of having a generic form (the ‘main’ form) that I use to hold the elements that will be used throughout the solution.
I copied this model from an example solution a while ago. Also, I found out that by using this approach (of having a ‘main’ form with all of the forms within) the solution seems more steady (there is no blinking while moving from forms) — especially if you are using Patrick’s Browser Suite to displayed the website of each customer (for example).
Thanks for your reply! I’ll figure something out. ![Smile :-)]()
Hi Carlos,
If you want to have a main navigation form you can do that easily.
Just have your main form with your buttons (if any) and a tabpanel without any tabs (tabOrientation set to ‘hide’).
Now you can add (non-related) tabs on the fly using elements.mainTabpanel.addTab(forms.myFormName)
Then you can just set the tabIndex of the main tabpanel to switch to that form.
To reset the tabpanel you just use elements.mainTabpabel.removeAllTabs().
Hope this helps.
ROCLASI:
… have your main form with your buttons (if any) and a tabpanel without any tabs (tabOrientation set to ‘hide’).
Now you can add (non-related) tabs on the fly using elements.mainTabpanel.addTab(forms.myFormName)
Then you can just set the tabIndex of the main tabpanel to switch to that form.
To reset the tabpanel you just use elements.mainTabpabel.removeAllTabs()…
That’s what I think I have, but I am not setting the tabs on the fly. Yes, they are unrelated tabs and each tab points to a form which actually have specified dataSource. The navigation is working fine. The problem is the having a ‘main’ form with not dataSource does not allow me to use some dataSource associated features. I probably need to change my approach and just use a ‘navigation’ instead of a ‘main’ form. Correct?