Wijmo UI for the Web
Create Dynamic Tabs
Show AllShow All
Hide AllHide All

Building on the Quick Start example, you can use the add method and the tabTemplate option along with the Dialog widget to create dynamic tabs. You can use the remove method and the CSS style class "ui-icon-close" to supply a button to delete tabs.

For a complete listing of the CSS styling elements available for this widget, in your installation folder under Wijmo, open the wijtabs folder and see the jquery.wijmo.wijtabs.css file.

For a complete listing of the CSS styling elements available for the Dialog widget, in your installation folder under Wijmo, open the wijdialog folder and see the jquery.wijmo.wijdialog.css file.

  1. In the <head> section of your HTML file, replace the script that includes the document ready function with this one, which  initializes the tab widget, sets tab widget options, creates an Add Tab function, and initializes and customizes a Dialog widget.

    Tab Widget and Add Tab Function

    • Sets the sortable option to true, allowing users to reorder tabs by dragging them into new positions.
    • Sets the tab title and tab content to get values from the dialog box.
    • Sets the tab counter to append a tab in the third position, after the two existing tabs.
    • Sets the tabTemplate up to use the <li> element to render tabs.
    • Creates the add function to append a new tab in the widget when called.

    Dialog Widget

    • Sets the autoOpen option to false, so that the dialog box only opens when you click the button.
    • Sets the modal option to true, so that the rest of the page is disabled until the dialog box is dismissed.
    • Adds Add and Cancel buttons to the dialog box, and sets up open and close functions.
    • Connects the dialog to the addTab function.
    • Sets the addTab function to collect information from the counter and the dialog box.
    • Sets the Add Tab button to open the dialog box.
    • Sets up the close icon to remove tabs on click.

    Drop down and copy script to paste in <head> section

  2. In the <body> section of your HTML file, replace the basic markup with this markup that includes a button. The first <div> element creates the tabs widget; its id option is set to 'tabs', which we call in the jQuery script to initialize the widget. The <ul> element sets the label text to show in the two tabs that show initially, and adds a Remove Tab button to each. The first nested <div> element contains content to display in the first tab. The second nested <div> element contains content to display in the second tab. Another <div> element adds a dialog box to allow users to set up their own tabs, and finally, an <input> element adds a button to call the dialog box.

    Drop down and copy markup to paste in <body> section

  3. In the <head> section of your HTML file, replace the style with this one, which styles the dialog and the close buttons.

    Drop down and copy styles to paste in <head> section

  4. Save your HTML file and open it in a browser. The widget appears like the one in the live widget below. Click the Add Tab button to open the dialog and add a tab. Click the x button in the corner of a tab to remove it.

See Also

Widgets

Concepts

Reference

 
Support Options