Class WTable

    • Constructor Detail

      • WTable

        public WTable()
        Creates a WTable.
    • Method Detail

      • setRenderColumnFooters

        public void setRenderColumnFooters​(boolean renderColumnFooters)
        Parameters:
        renderColumnFooters - true if render column footers
      • isRenderColumnFooters

        public boolean isRenderColumnFooters()
        Control if column footers should be rendered.

        When true, column footers are rendered on each page. Projects who need to control which page the footers are rendered on (e.g last page) can override this method.

        Returns:
        true if render column footers
      • addColumn

        public void addColumn​(WTableColumn column)
        Adds a column to the table.
        Parameters:
        column - the column to add.
      • getColumn

        public WTableColumn getColumn​(int index)
        Retrieves the column at the specified index. Bounds checking is not performed, see getColumnCount().
        Parameters:
        index - the column index. Zero based.
        Returns:
        the column at the specified index.
      • getColumnCount

        public int getColumnCount()
        Returns the number of columns contained in this table. Invisible columns still count towards the total.
        Returns:
        the number of columns contained in this table.
      • getRepeater

        public WTable.TableRepeater getRepeater()
        Returns:
        the repeater used to render table rows.
      • setTableModel

        public void setTableModel​(WTable.TableModel tableModel)
        Sets the table model which provides the row/column data.
        Parameters:
        tableModel - the table model.
      • getSeparatorType

        public WTable.SeparatorType getSeparatorType()
        Returns:
        the separator type used to visually separate rows or columns.
      • setSeparatorType

        public void setSeparatorType​(WTable.SeparatorType separatorType)
        Sets the separator used to visually separate rows or columns.
        Parameters:
        separatorType - the separator type to set.
      • setToggleSubRowSelection

        public void setToggleSubRowSelection​(boolean toggleSubRowSelection)
        Sets whether the de/selection of a row with sub rows should de/select the sub rows. This is a client-side only feature.
        Parameters:
        toggleSubRowSelection - true to turn on this feature.
      • isToggleSubRowSelection

        public boolean isToggleSubRowSelection()
        Indicates whether de/selecting a row with sub row(s) will de/select the sub row(s).
        Returns:
        true if this feature is enabled.
      • getStripingType

        public WTable.StripingType getStripingType()
        Returns:
        the striping type used to highlight alternate rows or columns
      • setStripingType

        public void setStripingType​(WTable.StripingType stripingType)
        Sets the striping type used to highlight alternate rows or columns.
        Parameters:
        stripingType - the striping type to set.
      • isShowColumnHeaders

        public boolean isShowColumnHeaders()
        Indicates whether table column headers should be displayed.
        Returns:
        true if column headers should be displayed, false otherwise.
      • setShowColumnHeaders

        public void setShowColumnHeaders​(boolean showColumnHeaders)
        Sets whether table column headers should be displayed.
        Parameters:
        showColumnHeaders - true to display table column headers, false otherwise.
      • getSelectionChangeAction

        public Action getSelectionChangeAction()
        Returns:
        the action to execute when row selection changes.
      • setSelectionChangeAction

        public void setSelectionChangeAction​(Action selectionChangeAction)
        Sets the action to execute when row selection changes.
        Parameters:
        selectionChangeAction - the action to execute on row selection change.
      • getNoDataMessage

        public String getNoDataMessage()
        Returns:
        the message to display when the table contains no rows.
      • setNoDataMessage

        public void setNoDataMessage​(String noDataMessage)
        Sets the message to display when the table contains no rows.
        Parameters:
        noDataMessage - the no data message.
      • getSummary

        @Deprecated
        public String getSummary()
        Deprecated.
        the summary field has been removed from the client side. API preserved temporarily for backwards compatibility.
        Returns:
        the table summary text.
      • setSummary

        @Deprecated
        public void setSummary​(String summary)
        Deprecated.
        the summary field has been removed from the client side. API preserved temporarily for backwards compatibility.
        Sets the table summary text.
        Parameters:
        summary - the table summary text to set.
      • getCaption

        public String getCaption()
        Returns:
        the table caption text.
      • setCaption

        public void setCaption​(String caption)
        Sets the table caption text.
        Parameters:
        caption - the table caption text to set.
      • getColumnOrder

        public int[] getColumnOrder()
        Returns:
        the column order, or null if the default ordering is to be used.
      • setColumnOrder

        public void setColumnOrder​(int[] columnOrder)
        Provide an array of column indexes in the order they should be rendered. At least one column must be specifed.

        This can also be used to "hide" columns by not including them in the array.

        Parameters:
        columnOrder - the column order to set, or null to use default ordering.
      • setMargin

        public void setMargin​(Margin margin)
        Set the margin for the component, or null for no margin.
        Specified by:
        setMargin in interface Marginable
        Parameters:
        margin - the margin for the component
      • getMargin

        public Margin getMargin()
        Get the margin for the component, or null if not set.
        Specified by:
        getMargin in interface Marginable
        Returns:
        the margin for the component, or null if not set
      • setPaginationMode

        public void setPaginationMode​(WTable.PaginationMode paginationMode)
        Sets the pagination mode.
        Parameters:
        paginationMode - the paginationMode to set.
      • getRowsPerPage

        public int getRowsPerPage()
        The number of rows to display per page. A value of zero, which is only valid when used with setRowsPerPageOptions(java.util.List), indicates display all rows.
        Returns:
        the number of rows to display per page.
      • setRowsPerPage

        public void setRowsPerPage​(int rowsPerPage)
        Sets the number of rows to display per page when pagination is enabled.

        If rows per page options have been set, then the value must be a valid option, which can include zero to indicate show all rows, otherwise the value must be greater than zero.

        Parameters:
        rowsPerPage - the rowsPerPage to set
      • getRowsPerPageOptions

        public List<Integer> getRowsPerPageOptions()
        Returns:
        the rows per page options, otherwise null
      • setRowsPerPageOptions

        public void setRowsPerPageOptions​(List<Integer> rowsPerPageOptions)
        Set the rows per page options.

        If the current value of getRowsPerPage() is not a valid option, it will be set to the first option.

        Parameters:
        rowsPerPageOptions - the rows per page options
      • isPaginated

        public boolean isPaginated()
        Returns:
        true if table is currently displaying paginated rows
      • getPaginationLocation

        public WTable.PaginationLocation getPaginationLocation()
        Returns:
        the location for the pagination controls
      • setPaginationLocation

        public void setPaginationLocation​(WTable.PaginationLocation location)
        Sets the location in the table to show the pagination controls.
        Parameters:
        location - the PaginationLocation to set.
      • getSelectMode

        public WTable.SelectMode getSelectMode()
        Returns:
        the row selection mode.
      • setSelectMode

        public void setSelectMode​(WTable.SelectMode selectMode)
        Sets the row selection mode.
        Parameters:
        selectMode - the row selection mode to set.
      • getSortMode

        public WTable.SortMode getSortMode()
        Returns:
        the sort mode.
      • setSortMode

        public void setSortMode​(WTable.SortMode sortMode)
        Sets the table sort mode. The data model controls which columns are sortable.
        Parameters:
        sortMode - The sort mode to set.
      • isEditable

        public boolean isEditable()

        For tables that are editable, extra details about each row must be stored to allow them to be updated. Therefore, if the table is not editable, the table is able to have improved performance.

        Returns:
        true if table is editable
      • setEditable

        public void setEditable​(boolean editable)
        Sets the table to be editable.

        For tables that are editable, extra details about each row must be stored to allow them to be updated. Therefore, if the table is not editable, the table is able to have improved performance.

        Parameters:
        editable - true if editable
      • getType

        public WTable.Type getType()
        Returns:
        the table type that controls how the table is displayed.
      • setType

        public void setType​(WTable.Type type)
        Sets the table type that controls how the table is displayed.
        Parameters:
        type - the table type to set.
      • getSelectAllMode

        public WTable.SelectAllType getSelectAllMode()
        Indicates how the table row "select all" function should be displayed.
        Returns:
        the select all mode.
      • setSelectAllMode

        public void setSelectAllMode​(WTable.SelectAllType selectAllMode)
        Sets how the table row "select all" function should be displayed.
        Parameters:
        selectAllMode - the select all mode to set.
      • getExpandMode

        public WTable.ExpandMode getExpandMode()
        Returns:
        the row expansion mode.
      • setExpandMode

        public void setExpandMode​(WTable.ExpandMode expandMode)
        Sets the row expansion mode.
        Parameters:
        expandMode - the expand mode to set.
      • isExpandAll

        public boolean isExpandAll()
        Indicates whether the "expand all" control should be available.
        Returns:
        true if the expand all control should be available, false if not.
      • setRowHeaders

        public void setRowHeaders​(boolean rowHeaders)
        Set the table as having row headers.
        Parameters:
        rowHeaders - indicates that the first data column in the table should be considered a row header.
      • isRowHeaders

        public boolean isRowHeaders()
        Returns:
        is the first data column a row header column?
      • setExpandAll

        public void setExpandAll​(boolean expandAll)
        Sets whether the "expand all" control should be available.
        Parameters:
        expandAll - true if the expand-all control should be available, false if not.
      • getCurrentPage

        public int getCurrentPage()
        Returns:
        the current page. Zero based.
      • setCurrentPage

        public void setCurrentPage​(int currentPage)
        Parameters:
        currentPage - the currentPage to set. Zero based.
      • setExpandedRows

        public void setExpandedRows​(Set<?> rowKeys)
        Set the row keys that are expanded.

        A row key uniquely identifies each row and is determined by the WTable.TableModel. Refer to WTable.TableModel.getRowKey(List).

        Parameters:
        rowKeys - the keys of expanded rows.
      • setSelectedRows

        public void setSelectedRows​(Set<?> rowKeys)
        Set the row keys that are selected.

        A row key uniquely identifies each row and is determined by the WTable.TableModel. Refer to WTable.TableModel.getRowKey(List).

        Parameters:
        rowKeys - the keys of selected rows.
      • getPrevExpandedRows

        protected Set<?> getPrevExpandedRows()
        Return the row keys that have been expanded.

        Note - Only used for when the table is editable.

        Returns:
        the previously expanded row keys.
      • addPrevExpandedRow

        protected void addPrevExpandedRow​(Object rowKey)
        Track the row keys that have been expanded.

        Note - Only used for when the table is editable.

        Parameters:
        rowKey - the row key that has been expanded.
      • clearPrevExpandedRows

        protected void clearPrevExpandedRows()
        Clear the previously expanded row keys.

        Note - Only used for when the table is editable.

      • getPrevRenderedRows

        protected Set<?> getPrevRenderedRows()
        Return the row keys that have been rendered.

        Note - Only used for when the table is editable.

        Returns:
        the previously rendered row keys.
      • addPrevRenderedRow

        protected void addPrevRenderedRow​(Object rowKey)
        Track the row keys that have been rendered.

        Note - Only used for when the table is editable.

        Parameters:
        rowKey - the row key that has been rendered.
      • clearPrevRenderedRows

        protected void clearPrevRenderedRows()
        Clear the previously rendered row keys.

        Note - Only used for when the table is editable.

      • setSort

        protected void setSort​(int index,
                               boolean ascending)
        For rendering purposes only - has no effect on model.
        Parameters:
        index - the sort column index, or -1 for no sort.
        ascending - true for ascending order, false for descending
      • isSorted

        public boolean isSorted()
        Returns:
        true if the table is currently sorted
      • getSortColumnIndex

        public int getSortColumnIndex()
        Returns:
        the index of the column the table is sorted by.
      • isSortAscending

        public boolean isSortAscending()
        Indicates whether the sort on this table is ascending. Note that a return value of false does not necessarily indicate a descending sort - see isSorted().
        Returns:
        true if the sort order is ascending, false for descending.
      • isSortable

        public boolean isSortable()
        Indicates whether the table supports sorting.
        Returns:
        true if the table and model both support sorting, false otherwise.
      • getActions

        public List<WButton> getActions()
        Retrieves the actions for the table.
        Returns:
        the list of table actions
      • addAction

        public void addAction​(WButton button)
        Adds a component to the set of table actions.
        Parameters:
        button - the button to add.
      • addActionConstraint

        public void addActionConstraint​(WButton button,
                                        WTable.ActionConstraint constraint)
        Adds a constraint to when the given action can be used.
        Parameters:
        button - the button which the constraint applies to.
        constraint - the constraint to add.
      • getActionConstraints

        public List<WTable.ActionConstraint> getActionConstraints​(WButton button)
        Retrieves the constraints for the given action.
        Parameters:
        button - the button to retrieve the constraints for.
        Returns:
        the constraints for the given action, or null if there are no constraints.
      • handleRequest

        public void handleRequest​(Request request)
        Override handleRequest to add table-specific functionality such as pagination and row selection.
        Specified by:
        handleRequest in interface WComponent
        Overrides:
        handleRequest in class AbstractWComponent
        Parameters:
        request - the request being responded to.
      • isPresent

        protected boolean isPresent​(Request request)
        Indicates whether this table was present in the request.
        Parameters:
        request - the request being responded to.
        Returns:
        true if this table was present in the request, false if not.
      • sort

        public void sort​(int sortCol,
                         boolean sortAsc)
        Sort the table data by the specified column.
        Parameters:
        sortCol - the column to sort
        sortAsc - true if sort ascending, otherwise sort descending
      • handleDataChanged

        public void handleDataChanged()
        Method to call when the model data has changed. For example, when a row has been added or removed.

        Handles resorting the data (if table sorted) and making sure the table pagination is still correct.

      • getRowIdName

        protected String getRowIdName​(List<Integer> rowIndex,
                                      Object rowKey)
        Allows a subclass to provide the ID used in the row naming context. It is important this ID is unique for each row.

        The returned ID must only contain letters, digits or underscores.

        Parameters:
        rowIndex - the current row index
        rowKey - the current row key.
        Returns:
        the unique row id or null to use the default context id
      • getChildCount

        public int getChildCount()
        Specified by:
        getChildCount in interface Container
        Returns:
        the number of child components currently contained within this component.
      • getChildAt

        public WComponent getChildAt​(int index)
        Retrieves a child component by its index.
        Specified by:
        getChildAt in interface Container
        Parameters:
        index - the index of the child component to be retrieved.
        Returns:
        the child component at the given index.
      • getIndexOfChild

        public int getIndexOfChild​(WComponent childComponent)
        Retrieves the index of the given child.
        Specified by:
        getIndexOfChild in interface Container
        Parameters:
        childComponent - the child component to retrieve the index for.
        Returns:
        the index of the given child component, or -1 if the component is not a child of this component.
      • getChildren

        public List<WComponent> getChildren()
        Retrieves a list of this Container's.
        Specified by:
        getChildren in interface Container
        Returns:
        an immutable list of this Container.
      • toString

        public String toString()
        Description copied from class: AbstractWComponent
        Creates a String representation of this component; usually for debugging purposes.
        Overrides:
        toString in class AbstractWComponent
        Returns:
        a String representation of this component, for debugging purposes.
      • isNamingContext

        public boolean isNamingContext()
        A naming context is only considered active if an Id name has been set.
        Specified by:
        isNamingContext in interface NamingContextable
        Returns:
        true if active naming context.
      • getComponentModel

        protected WTable.WTableComponentModel getComponentModel()
        Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.
        Overrides:
        getComponentModel in class WBeanComponent
        Returns:
        the effective component model
      • getOrCreateComponentModel

        protected WTable.WTableComponentModel getOrCreateComponentModel()
        Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.
        Overrides:
        getOrCreateComponentModel in class WBeanComponent
        Returns:
        the model for this component