Options
All
  • Public
  • Public/Protected
  • All
Menu

PrimeFaces ColumnToggler Widget

ColumnToggler is a helper component for the data table to toggle visibility of columns.

Type Parameters

Hierarchy

Index

Constructors

  • Creates a new instance of this widget. Please note that you should NOT override this constructor. Instead, override the init method, which is called at the end of the constructor once the instance is created.

    Type Parameters

    Parameters

    • cfg: PartialWidgetCfg<TCfg>

      The widget configuration to be used for this widget instance. This widget configuration is usually created on the server by the javax.faces.render.Renderer for this component.

    Returns ColumnToggler<TCfg>

Properties

cfg: PartialWidgetCfg<TCfg>

The configuration of this widget instance. Please note that no property is guaranteed to be present, you should always check for undefined before accessing a property. This is partly because the value of a property is not transmitted from the server to the client when it equals the default.

closer?: JQuery<HTMLElement>

DOM element of the close button for closing the overlay with the available columns.

columns?: JQuery<HTMLElement>

DOM elements for the TH columns of the data table.

Array of registered listeners invoked when this widget is destroyed. You should normally not use modify this directly, use addDestroyListener instead.

frozenColumnCount?: number

The number of frozen column of table to which this column toggle is attached.

hasFrozenColumn: boolean

Whether the table to which this column toggle is attached has got any frozen columns.

hasPriorityColumns?: boolean

Whether any prioritized columns exist. Used for responsive mode.

hasStickyHeader: boolean

Whether the table to which this column toggle is attached has got a sticky header.

id: string | string[]

The client-side ID of this widget, with all parent naming containers, such as myForm:myWidget. This is also the ID of the container HTML element for this widget. In case the widget needs multiple container elements (such as Paginator), this may also be an array if IDs.

itemContainer?: JQuery<HTMLElement>

DOM elements for the UL items in the overlay with the available columns.

jq: JQuery<HTMLElement>

The jQuery instance of the container element of this widget. In case id is an array, it will contain multiple elements. Please note that some widgets have got not DOM elements at all, in this case this will be an empty jQuery instance.

jqId: string

A CSS selector for the container element (or elements, in case id is an array) of this widget, This is usually an ID selector (that is properly escaped). You can select the container element or elements like this: $(widget.jqId).

panel?: JQuery<HTMLElement>

Overlay column toggler panel with the available columns.

Array of registered listeners invoked when this widget is refreshed. You should normally not use modify this directly, use addRefreshListener instead.

selectAllCheckbox?: JQuery<HTMLElement>

DOM element for the select all checkbox.

table: JQuery<HTMLElement>

Table to which this column toggle is attached.

tableId: string

ID of the table to which this column toggle is attached.

tbody: JQuery<HTMLElement>

The DOM element for the table body of the table to which this column toggle is attached.

tfoot: JQuery<HTMLElement>

The DOM element for the table foot of the table to which this column toggle is attached.

thead: JQuery<HTMLElement>

The DOM element for the table head of the table to which this column toggle is attached.

togglerState?: string[]

IDs of the columns that are selected.

togglerStateHolder?: JQuery<HTMLElement>

DOM element of the hidden input that contains the columns that are selected. Used to preserve that state between AJAX updates.

trigger: JQuery<HTMLElement>

Button that toggles this column toggler.

visible: boolean

Whether this column toggler is currently displayed.

widgetVar: string

The name of the widget variables of this widget. The widget variable can be used to access a widget instance by calling PF('myWidgetVar').

widthAligned?: boolean

Whether the width of the overlay panel with the available columns was aligned with the width of the toggler.

Methods

  • _render(): void
  • This render method is called by this deferred widget once the widget container has become visible. You may now proceed with widget initialization.

    Must be overridden, or an error will be thrown.

    override

    Returns void

  • addDeferredRender(widgetId: string, container: JQuery<HTMLElement>, callback: (() => boolean)): void
  • Adds a deferred rendering task for the given widget to the queue.

    Parameters

    • widgetId: string

      The ID of a deferred widget.

    • container: JQuery<HTMLElement>

      The container element that should be visible.

    • callback: (() => boolean)

      Callback that is invoked when the widget may possibly have become visible. Should return true when the widget was rendered, or false when the widget still needs to be rendered later.

        • (): boolean
        • Returns boolean

    Returns void

  • Lets you register a listener that is called before the component is destroyed.

    When an AJAX call is made and this component is updated, the DOM element is replaced with the newly rendered content. When the element is removed from the DOM by the update, the DOM element is detached from the DOM and all destroy listeners are called. This makes it possible to add listeners from outside the widget code.

    If you call this method twice with the same listener, it will be registered twice and later also called twice.

    Note that for this to work, you must not override the destroy method; or if you do, call super.

    Also, after this widget was detached is done, all destroy listeners will be unregistered.

    since

    7.0

    Parameters

    Returns void

  • When an AJAX call is made and this component is updated, the DOM element is replaced with the newly rendered content. However, no new instance of the widget is created. Instead, after the DOM element was replaced, all refresh listeners are called. This makes it possible to add listeners from outside the widget code.

    If you call this method twice with the same listener, it will be registered twice and later also called twice.

    Note that for this to work, you must not override the refresh method; or if you do, call super.

    Also, after the refresh is done, all refresh listeners will be deregistered. If you added the listeners from within this widget, consider adding the refresh listeners not only in the init method, but also again in the refresh method after calling super.

    since

    7.0.0

    Parameters

    Returns void

  • alignPanel(): void
  • Aligns the overlay panel of this column toggler according to the current widget configuration.

    Returns void

  • bindEvents(): void
  • Sets up all event listeners required by this widget.

    Returns void

  • bindKeyEvents(): void
  • Sets up the event listners for keyboard interaction.

    Returns void

  • calculateColspan(): number
  • Computes the required colspan for the rows.

    Returns number

    The calculated colspan for the rows.

  • Each widget may have one or several behaviors attached to it. This method calls all attached behaviors for the given event name. In case no such behavior exists, this method does nothing and returns immediately.

    A behavior is a way for associating client-side scripts with UI components that opens all sorts of possibilities, including client-side validation, DOM and style manipulation, keyboard handling, and more. When the behavior is triggered, the configured JavaScript gets executed.

    Behaviors are often, but not necessarily, AJAX behavior. When triggered, it initiates a request the server and processes the response once it is received. This enables several features such as updating or replacing elements dynamically. You can add an AJAX behavior via <p:ajax event="name" actionListener="#{...}" onstart="..." />.

    since

    7.0

    Parameters

    • event: string

      The name of an event to call.

    • Optional ext: Partial<ConfigurationExtender>

      Additional configuration that is passed to the AJAX request for the server-side callback.

    Returns void

  • changeTogglerState(column: JQuery<HTMLElement>, isHidden: boolean): void
  • Selects or unselect a column of this column toggler. Also shows or hides the corresponding colum of the table to which this column toggler is attached.

    Parameters

    • column: JQuery<HTMLElement>

      A column element (LI) of this column toggler.

    • isHidden: boolean

      true to unselect the column and hide the corresponding table column, or true otherwise.

    Returns void

  • check(chkbox: JQuery<HTMLElement>): void
  • Checks the given checkbox for a column, so that the column is now selected. Also display the column of the table to which this column toggler is attached.

    Parameters

    • chkbox: JQuery<HTMLElement>

      Checkbox (.ui-chkbox-box) of a column of this column toggler.

    Returns void

  • checkAll(): void
  • Checks all columns to enable all.

    Returns void

  • destroy(): void
  • Cleans up deferred render tasks. When you extend this class and override this method, make sure to call super.

    override

    Returns void

  • fireCloseEvent(): void
  • Triggers the events listeners and behaviors when the popup is closed.

    Returns void

  • fireToggleEvent(visible: boolean, index: number): void
  • Triggers the events listeners and behaviors when a column was selected or unselected.

    Parameters

    • visible: boolean

      true if the column was selected, false otherwise.

    • index: number

      Index of the toggled column.

    Returns void

  • getBehavior(name: string): null | Behavior
  • Each widget may have one or several behaviors attached to it. This method returns the callback function for the given event.

    Note: Do not call the method directly, the recommended way to invoke a behavior is via callBehavior.

    A behavior is a way for associating client-side scripts with UI components that opens all sorts of possibilities, including client-side validation, DOM and style manipulation, keyboard handling, and more. When the behavior is triggered, the configured JavaScript gets executed.

    Behaviors are often, but not necessarily, AJAX behavior. When triggered, it initiates a request the server and processes the response once it is received. This enables several features such as updating or replacing elements dynamically. You can add an AJAX behavior via <p:ajax event="name" actionListener="#{...}" onstart="..." />.

    Parameters

    • name: string

      The name of an event for which to retrieve the behavior.

    Returns null | Behavior

    The behavior with the given name, or null if no such behavior exists.

  • Each widget has got a container element, this method returns that container. This container element is usually also the element whose ID is the client-side ID of the JSF component.

    Returns JQuery<HTMLElement>

    The jQuery instance representing the main HTML container element of this widget.

  • getParentForm(): JQuery<HTMLElement>
  • Gets the closest parent form for this widget.

    since

    10.0.0

    Returns JQuery<HTMLElement>

    A JQuery instance that either contains the form when found, or an empty JQuery instance when the form could not be found.

  • getParentFormId(): undefined | string
  • Gets the closest parent form ID for this widget lazily so it can be used in AJAX requests.

    since

    10.0.0

    Returns undefined | string

    Either the form ID or undefined if no form can be found.

  • hasBehavior(event: string): boolean
  • Each widget may have one or several behaviors attached to it. This method checks whether this widget has got at least one behavior associated with given event name.

    A behavior is a way for associating client-side scripts with UI components that opens all sorts of possibilities, including client-side validation, DOM and style manipulation, keyboard handling, and more. When the behavior is triggered, the configured JavaScript gets executed.

    Behaviors are often, but not necessarily, AJAX behavior. When triggered, it initiates a request the server and processes the response once it is received. This enables several features such as updating or replacing elements dynamically. You can add an AJAX behavior via <p:ajax event="name" actionListener="#{...}" onstart="..." />.

    Parameters

    • event: string

      The name of an event to check.

    Returns boolean

    true if this widget has the given behavior, false otherwise.

  • hide(): void
  • Hides this column toggler.

    Returns void

  • A widget class should not declare an explicit constructor, the default constructor provided by this base widget should be used. Instead, override this initialize method which is called after the widget instance was constructed. You can use this method to perform any initialization that is required. For widgets that need to create custom HTML on the client-side this is also the place where you should call your render method.

    Please make sure to call the super method first before adding your own custom logic to the init method:

    PrimeFaces.widget.MyWidget = PrimeFaces.widget.BaseWidget.extend({
    init: function(cfg) {
    this._super(cfg);
    // custom initialization
    }
    });
    override

    Parameters

    • cfg: PartialWidgetCfg<TCfg>

      The widget configuration to be used for this widget instance. This widget configuration is usually created on the server by the javax.faces.render.Renderer for this component.

    Returns void

  • isDetached(): boolean
  • Checks if this widget is detached, ie whether the HTML element of this widget is currently contained within the DOM (the HTML body element). A widget may become detached during an AJAX update, and it may remain detached in case the update removed this component from the component tree.

    Returns boolean

    true if this widget is currently detached, or false otherwise.

  • postRender(): void
  • Called after the widget has become visible and after it was rendered. May be overridden, the default implementation is a no-op.

    Returns void

  • Used in ajax updates, reloads the widget configuration.

    When an AJAX call is made and this component is updated, the DOM element is replaced with the newly rendered content. However, no new instance of the widget is created. Instead, after the DOM element was replaced, this method is called with the new widget configuration from the server. This makes it possible to persist client-side state during an update, such as the currently selected tab.

    Please note that instead of overriding this method, you should consider adding a refresh listener instead via addRefreshListener. This has the advantage of letting you add multiple listeners, and makes it possible to add additional listeners from code outside this widget.

    By default, this method calls all refresh listeners, then reinitializes the widget by calling the init method.

    override

    Parameters

    Returns void

    The value as returned by the init method, which is often undefined.

  • removeScriptElement(clientId: string | string[]): void
  • Removes the widget's script block from the DOM. Currently, the ID of this script block consists of the client-side ID of this widget with the prefix _s, but this is subject to change.

    Parameters

    • clientId: string | string[]

      The client-side ID of the widget.

    Returns void

  • render(): void
  • This render method to check whether the widget container is visible. Do not override this method, or the deferred widget functionality may not work properly anymore.

    override

    Returns void

    true if the widget container is visible, false or undefined otherwise.

  • renderDeferred(): void
  • Call this method in the init method if you want deferred rendering support. This method checks whether the container of this widget is visible and call _render only once it is.

    Returns void

  • show(): void
  • Brings up this column toggler so that the user can which column to hide or show.

    Returns void

  • toggle(chkbox: JQuery<HTMLElement>): void
  • Checks or unchecks the given checkbox for a column, depending on whether it is currently selected. Also shows or hides the column of the table to which this column toggler is attached.

    Parameters

    • chkbox: JQuery<HTMLElement>

      Checkbox (.ui-chkbox-box) of a column of this column toggler.

    Returns void

  • toggleAll(): void
  • Toggles selecting or deselecting all columns.

    Returns void

  • uncheck(chkbox: JQuery<HTMLElement>): void
  • Unchecks the given checkbox for a column, so that the column is now not selected. Also hides the column of the table to which this column toggler is attached.

    Parameters

    • chkbox: JQuery<HTMLElement>

      Checkbox (.ui-chkbox-box) of a column of this column toggler.

    Returns void

  • uncheckAll(): void
  • Unchecks all columns to disable all.

    Returns void

  • updateColspan(): void
  • Updates the colspan attributes of the target table of this column toggler. Called after a column was selected or unselected, which resulted in a column of the data table to be shown or hidden.

    Returns void

  • updateRowColspan(row: JQuery<HTMLElement>, colspanValue: string): void
  • Updates the colspan attribute fo the columns of the given row.

    Parameters

    • row: JQuery<HTMLElement>

      A row to update.

    • colspanValue: string

      New value for the colspan attribute.

    Returns void

Generated using TypeDoc