Add widgets dynamically
By using a special
addWidget component it is possible to fill up a dynaWidget grid dynamically.
With this component applications can offer a range of widgets for users to add to their individual grid.
Using the addWidget component
<dwComp:addWidget
widgetGridId="myDynamicGrid"
widgetId="secondWidget"
value="click to add 'MySecondWidget' to grid"
initialState="{'title':'My second widget','commandEdit':'false'}"/>
the grid:
<dwComp:dynaWidgetGrid id="myDynamicGrid"
...
defaultStateStore="server"
initialState="{...}" />
What´s important here:
- addWidget must be configured for a dynaWidget grid id and a dynaWidget id
- The initial state of the widget is set by the json string initialState which has the form:
{'title':'the widget´s title',...}
- for adding widgets to a dynaWidget grid it must have a configured (default)StateStore , see state management section.
For details on using the dynaWidget components see
main components.
An example for the addWidget component
In the following example you can choose between adding 3 different widgets (which you might already know from the first example) to the grid.
The same widget can only be added once - therefore it has to be removed (using the close action) before adding it again. Give it a try and play around with it!