Class DataGrid<D extends IDataSource<T>,​T,​S>

    • Constructor Detail

      • DataGrid

        public DataGrid​(String id,
                        IModel<D> model,
                        List<IGridColumn<D,​T,​S>> columns)
        Crates a new DataGrid instance.
        Parameters:
        id - component id
        model - model to access the IDataSource instance used to fetch the data
        columns - list of grid columns
      • DataGrid

        public DataGrid​(String id,
                        D dataSource,
                        List<IGridColumn<D,​T,​S>> columns)
        Crates a new DataGrid instance.
        Parameters:
        id - component id
        dataSource - data source used to fetch the data
        columns - list of grid columns
    • Method Detail

      • getDataSource

        public D getDataSource()
        Returns the IDataSource instance this data grid uses to fetch the data.
        Returns:
        IDataSource instance
      • setRowsPerPage

        public DataGrid<D,​T,​S> setRowsPerPage​(int rowsPerPage)
        Sets the desired amount rows per page.
        Parameters:
        rowsPerPage - how many rows (max) should be displayed on one page
        Returns:
        this (useful for method chaining)
      • getRowsPerPage

        public long getRowsPerPage()
        Returns the maximal amount of rows shown on one page.
        Returns:
        count of rows per page
      • getTotalRowCount

        public long getTotalRowCount()
        Returns the total count of items (sum of count of items on all pages) or AbstractPageableView.UNKNOWN_COUNT in case the count can't be determined.
        Returns:
        total count of items or -1L
      • getCurrentPage

        public long getCurrentPage()
        Specified by:
        getCurrentPage in interface IPageable
        Returns:
        The current page that is or will be rendered.
      • getPageCount

        public long getPageCount()
        Gets the total number of pages this pageable object has.
        Specified by:
        getPageCount in interface IPageable
        Returns:
        The total number of pages this pageable object has
      • setCurrentPage

        public void setCurrentPage​(long page)
        Sets the a page that should be rendered.
        Specified by:
        setCurrentPage in interface IPageable
        Parameters:
        page - The page that should be rendered.
      • getCurrentPageItemCount

        public long getCurrentPageItemCount()
        Returns:
        the amount of items on current page.
      • isAllowSelectMultiple

        public boolean isAllowSelectMultiple()
        Returns whether user will be able to select more than one item at a time.
        Specified by:
        isAllowSelectMultiple in class AbstractGrid<D extends IDataSource<T>,​T,​S>
        Returns:
        true if multiple items can be selected at a time, false otherwise.
      • setAllowSelectMultiple

        public void setAllowSelectMultiple​(boolean value)
        Sets whether user will be able to select more than one item.
        Specified by:
        setAllowSelectMultiple in class AbstractGrid<D extends IDataSource<T>,​T,​S>
        Parameters:
        value - true if the user will be able to select more than one item at a time, false otherwise (single selection mode).
      • setCleanSelectionOnPageChange

        public DataGrid<D,​T,​S> setCleanSelectionOnPageChange​(boolean cleanSelectionOnPageChange)
        Sets whether the change of current page should clear all selected items. This means that only items on current page can be selected, i.e. items from multiple pages can not be selected at the same time.
        Parameters:
        cleanSelectionOnPageChange - whether the current page change should deselect all selected items
        Returns:
        this (useful for method chaining)
      • isCleanSelectionOnPageChange

        public boolean isCleanSelectionOnPageChange()
        Returns:
        whether the current page change cleans the selection
      • isItemSelected

        public boolean isItemSelected​(IModel<T> itemModel)
        Queries whether the item specified by itemModel is currently selected.
        Specified by:
        isItemSelected in class AbstractGrid<D extends IDataSource<T>,​T,​S>
        Parameters:
        itemModel - item model
        Returns:
        true if the item is selected, false otherwise
      • resetSelectedItems

        public void resetSelectedItems()
        Deselects all items. This method marks all items (not just visible items) as no selected.
        Specified by:
        resetSelectedItems in class AbstractGrid<D extends IDataSource<T>,​T,​S>
      • markItemDirty

        public void markItemDirty​(IModel<T> itemModel)
        Marks the item from the given model as dirty. Dirty items are updated during Ajax requests when AbstractGrid.update() method is called.
        Specified by:
        markItemDirty in class AbstractGrid<D extends IDataSource<T>,​T,​S>
        Parameters:
        itemModel - model used to access the item
      • markAllItemsDirty

        public void markAllItemsDirty()
        Makes the next call to update() refresh the entire grid.
      • onItemSelectionChanged

        public void onItemSelectionChanged​(IModel<T> item,
                                           boolean newValue)
        Invoked when an item selection state has been changed.
        Overrides:
        onItemSelectionChanged in class AbstractGrid<D extends IDataSource<T>,​T,​S>
        Parameters:
        item - item model
        newValue - true if the item became selected, false otherwise.
      • update

        public void update()
        During an Ajax request this method updates the changed grid rows.

        The definition of "changed" varies in DataGrid and TreeGrid.

        • In both grids the items for which the selection state changed are considered changed.
        • In TreeGrid the changes to TreeModel itself are being tracked (assuming the proper listeners are fired) and all rows that need to be updated are also considered changed.
        • In DataGrid the items that need to be updated can be marked by markItemDirty(IModel) or markAllItemsDirty(). The grid itself doesn't track changes to specific items (apart from the selection state).
        Specified by:
        update in class AbstractGrid<D extends IDataSource<T>,​T,​S>
      • insertRow

        public Item<T> insertRow​(T rowData)
        Insert the rowData into the grid
        Parameters:
        rowData - data to insert into the new row
        Returns:
        Item inserted Item
      • selectItem

        public void selectItem​(IModel<T> itemModel,
                               boolean selected)
        Alters the selection state of item specified by the item model.
        Specified by:
        selectItem in class AbstractGrid<D extends IDataSource<T>,​T,​S>
        Parameters:
        itemModel - item model
        selected - true if the item should be selected, false otherwise.