Creates cover grids: a flat array of items shown as tiles (book covers, photos, products) – as many per row as fit into the width of the table (floor(width / coverWidth)), without header and footer. Only the visible rows are rendered, like in every GuiExpert Table; filter (externalFilterFunction), sort() and the scroll position work as usual. Guide: instructions.md 5.10, showcase https://gui.expert/showcase/covergrid/run.

Example

interface Book { title: string; }
declare const books: Book[];

const renderer: CellRendererIf = {
render(cellDiv: HTMLDivElement, _r: number, _c: number, _a: AreaIdent, _m: AreaModelIf, book: any) {
if (book) cellDiv.textContent = (book as Book).title; // the item of this tile (undefined after the last one)
return undefined;
}
};
const gridModel = CoverGridFactory.createCoverGridModel(books, renderer, 160, 240);
const gridOptions = CoverGridFactory.createCoverGrisDefaultOptions(240, () => "books");
const gridApi = new TableScope(host, gridModel, new SimpleDomService(), gridOptions, new EventAdapter())
.firstInit()
.getApi();

Hierarchy

  • CoverGridFactory

Constructors

Methods

  • Creates the model of a cover grid.

    Type Parameters

    • T

    Parameters

    • items: T[]

      the items, one per tile (the renderer gets the item as cellValue)

    • cellRenderer: CellRendererIf

      draws one tile into the cell <div>

    • coverWidth: number = 200

      width of a tile in px (default 200) – change it later via bodyModel.coverWidth + repaintHard()

    • coverHeight: number = 300

      height of a tile in px (default 300)

    • width: number = 0

      initial width of the grid; the table sets the width of its host on start and after a resize

    • firstRowPaddingTop: number = 0

      extra height of the first row in px (room above the first tiles, e.g. for a toolbar)

    Returns CoverGridTableModel<T>

    the table model; tableModel.bodyModel holds items, filteredItems, coverWidth, coverHeight

    Example

    declare const renderer: CellRendererIf;
    const gridModel = CoverGridFactory.createCoverGridModel(["a.jpg", "b.jpg", "c.jpg"], renderer, 120, 180);
    // bigger tiles – no new model:
    gridModel.bodyModel.coverWidth = 200;
    gridModel.bodyModel.coverHeight = 300;
    tableApi.repaintHard();
  • Options for a cover grid: no borders and separators, no row or column hover, header and footer height 0, and the scroll position restored under the key of getStorageKeyFn (localStorage). (The name has a typo – kept for compatibility.)

    Parameters

    • defaultRowHeight: number

      the height of a tile (coverHeight)

    • getStorageKeyFn: (() => string) = ...

      storage key of the scroll position (default "CoverGrid")

        • (): string
        • Returns string

    Returns TableOptionsIf

    new options – add your own fields with a spread

    Example

    let photoFilter = "";
    const gridOptions: TableOptionsIf = {
    ...CoverGridFactory.createCoverGrisDefaultOptions(240, () => "photos"),
    externalFilterFunction: (photo: { name: string }) => photo.name.includes(photoFilter),
    shortcutActionsDisabled: true
    };