Options
All
  • Public
  • Public/Protected
  • All
Menu

Table powered by Angular Material library.

Example of usage

Simple table with built-in pagination, sort and search.

export const component: DraymanComponent = async ({ forceUpdate }) => {
    const data = [
        { name: { value: 'Carbon' }, weight: { value: 12.0107 }, symbol: { value: 'C' } },
        { name: { value: 'Hydrogen' }, weight: { value: 1.0079 }, symbol: { value: 'H' } },
        { name: { value: 'Fluorine' }, weight: { value: 18.9984 }, symbol: { value: 'F' } },
        { name: { value: 'Boron' }, weight: { value: 10.811 }, symbol: { value: 'B' } },
        { name: { value: 'Lithium' }, weight: { value: 6.941 }, symbol: { value: 'Li' } },
        { name: { value: 'Helium' }, weight: { value: 4.0026 }, symbol: { value: 'He' } },
        { name: { value: 'Neon' }, weight: { value: 20.1797 }, symbol: { value: 'Ne' } },
        { name: { value: 'Nitrogen' }, weight: { value: 14.0067 }, symbol: { value: 'N' } },
        { name: { value: 'Oxygen' }, weight: { value: 15.9994 }, symbol: { value: 'O' } },
        { name: { value: 'Beryllium' }, weight: { value: 9.0122 }, symbol: { value: 'Be' } },
    ];

    const columns = [{
        field: 'name',
        label: 'Name',
    }, {
        field: 'weight',
        label: 'Weight',
    }, {
        field: 'symbol',
        label: 'Symbol',
    }];

    return () => <drayman-table key="table" pagination sort search columns={columns} data={data} />;
}

Table with remote data, pagination and search (disableInternalProcessing set to true).

import axios from 'axios';

export const component: DraymanComponent = async ({ forceUpdate }) => {
    const API_KEY = ``;
    let data = [];
    let itemCount;
    let pageIndex = 0;
    let searchValue = 'brea';

    const getMovieResponse = async () => {
        const page = pageIndex + 1;
        const result = await axios.get(`https://api.themoviedb.org/3/search/movie?api_key=${API_KEY}&query=${searchValue}&page=${page}`);
        data = getTableData(result.data.results.map(x => ({ title: x.title, rating: x.vote_average })));
        pageIndex = result.data.page - 1;
        itemCount = result.data.total_results;
    }

    await getMovieResponse();

    return () => {
        const options = {
            data,
            columns: [{
                field: 'title',
                label: 'Title',
            }, {
                field: 'rating',
                label: 'Rating',
            }],
            pagination: true,
            pageSizeOptions: [],
            pageSize: 20,
            search: true,
            disableInternalProcessing: true,
            itemCount,
            pageIndex,
            initialSearchValue: searchValue,
            onPageChange: async (data) => {
                pageIndex = data.pageIndex;
                await getMovieResponse();
                await forceUpdate();
            },
            onSearchChange: async ({ value }) => {
                searchValue = value;
                await getMovieResponse();
                await forceUpdate();
            },
        }

        return <drayman-table {...options} />;
    };
}

function getTableData(data) {
    return data.map(x => Object.fromEntries(
        Object.entries(x).map(([key, value]) => [key, { value }])
    ));
}

Table with editable fields

export const component: DraymanComponent = async ({ forceUpdate }) => {
    const data = [];

    return () => {
        return <drayman-table
            data={data}
            columns={[{
                field: 'name',
                label: 'Name',
                type: 'text-field',
            }, {
                field: 'age',
                label: 'Age',
                type: 'number-field',
            }]}
            toolbarButtons={[{
                view: 'icon',
                icon: 'add'
            }]}
            onToolbarButtonClick={async ({ selectedRows, buttonDefinition }) => {
                data.push({
                    name: { value: null },
                    age: { value: null },
                    id: { value: data.length },
                });
                await forceUpdate();
            }}
            onCellValueChange={async ({ row, field, value }) => {
                const rowToEdit = data.find(x => x.id.value === row.id.value);
                rowToEdit[field].value = value;
                rowToEdit[field].error = field === 'age' && value < 18 ? 'Too young' : null;
                await forceUpdate();
            }}
            title="Editable data grid"
        />;
    };
}

Hierarchy

Index

Properties

columns

columns: DraymanTableColumn[]

Table column definitions.

data

data: DraymanTableRow[]

Table row data.

Optional disableHeader

disableHeader: boolean

Controls appearance of the column header.

Optional disableInternalProcessing

disableInternalProcessing: boolean

Disables internal pagination, sorting and search algorithms applied after every data change and firing of event. Allows to apply custom logic for pagination, sort and search.

Optional disableToolbar

disableToolbar: boolean

Controls appearance of the table toolbar.

Optional initialSearchValue

initialSearchValue: string

Initial value for search bar.

Optional itemCount

itemCount: number

Controls item count number shown in paginator if disableInternalProcessing is enabled.

Optional onCellButtonClick

onCellButtonClick: ElementEvent<{ field: string; row: DraymanTableRow; rowIndex: number }>

Event fired when user clicks a cell with the button type.

Optional onCellClick

onCellClick: ElementEvent<{ field: string; row: DraymanTableRow; rowIndex: number }>

Event fired when user clicks a cell.

Optional onCellDblClick

onCellDblClick: ElementEvent<{ field: string; row: DraymanTableRow; rowIndex: number }>

Event fired when user double-clicks a cell.

Optional onCellFocus

onCellFocus: ElementEvent<{ field: string; row: DraymanTableRow; rowIndex: number }>

Manages onFocus event.

Optional onCellValueChange

onCellValueChange: ElementEvent<{ field: string; row: DraymanTableRow; rowIndex: number; value: any }>

Event fired when user changes a value of cell with the text-field, number-field or selection.

Optional onFileUpload

onFileUpload: ElementEvent<{ field: string; row: DraymanTableRow; rowIndex: number }>

Executed when file is uploaded. This function contains uploaded file and must return a unique file ID. This unique ID is then used to revert uploads.

Optional onPageChange

onPageChange: ElementEvent<{ pageIndex: number; pageSize: number }>

Event fired when user changes a page or page size.

Optional onRemoveUploadedFile

onRemoveUploadedFile: ElementEvent<{ field: string; fileId: string; row: DraymanTableRow; rowIndex: number }>

Executed when user wants to remove a file. Receives unique file ID fileId. This function is usually used to remove a specific file from file system.

Optional onRowDragEnd

onRowDragEnd: ElementEvent<{ currentIndex: number; previousIndex: number; row: DraymanTableRow }>

Event fired when user rearranges some row.

Optional onSearchChange

onSearchChange: ElementEvent<{ value: string }>

Event fired when user performs a search.

Optional onSelectSearchChange

onSelectSearchChange: ElementEvent<{ field: string; row: DraymanTableRow; rowIndex: number; value: string }>

This function can be used to override default cells with select type search algorithm. Accepts value of the search input. Can be null. If this function is not defined, options will be filtered client-side.

Optional onSortChange

onSortChange: ElementEvent<{ field: string; order: "asc" | "desc" }>

Event fired when user performs a sort on some column.

Optional onToolbarButtonClick

onToolbarButtonClick: ElementEvent<{ buttonDefinition: DraymanToolbarButton; selectedRows: { row: DraymanTableRow; rowIndex: number }[] }>

Event fired when user clicks a toolbar button.

Optional pageIndex

pageIndex: number

Controls page index shown in paginator if disableInternalProcessing is enabled.

Optional pageSize

pageSize: number

Controls page size number shown in paginator if disableInternalProcessing is enabled.

Optional pageSizeOptions

pageSizeOptions: number[]

The set of provided page size options to display to the user. Defaults to [5, 10, 25, 100].

Optional pagination

pagination: boolean

Enables paginator.

Optional ref

ref: string

Optional rowDrag

rowDrag: boolean

Used to rearrange rows by dragging the row with the mouse. Row dragging will be disabled if pagination, sort or search is enabled.

Optional rowStyle

rowStyle: any[]

Style for each row in data.

Optional search

search: boolean

Enables search bar.

Optional select

select: boolean

Wether to enable row selection or not.

Optional sort

sort: boolean

Enables column sorting.

Optional style

style: CSS

Optional title

title: string

Title of the table. Table by default.

Optional toolbarButtons

toolbarButtons: DraymanToolbarButton[]

List of toolbar buttons.