1.0.0 • Published 4 years ago

react-yii-tools v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Import

    import { Yii2DataProvider } from 'react-yii-tools';

Example

    import React from 'react';

    //components
    import { Yii2DataProvider } from 'react-yii-tools';

    const createColumnsHeader = (name, label, number = false, isPrimary = false, showInTable = true, filter = true, rest) => {
        return {
            name,
            label,
            number,
            filter,
            isPrimary,
            showInTable,
            ...rest
        }
    }

    const columnsHeader = [
        createColumnsHeader('id', 'Id', true, true, false, true),
        createColumnsHeader('name', 'Name', true),
        createColumnsHeader('surname', 'Surname', false),
    ];

    export const Table = () => <Yii2DataProvider 
        api={{
            url:'https://localhost/yii2/web/api',
            headers: { 
                'Authorization': 'Bearer jwtToken'
            }
        }}
        actions={{
            show: '/show',
            delete: true,
            edit: '/edit'
        }}
        onSearch={action('search')}
        onEdit={action('edit')}
        //onDelete={action('delete')}
        filters={false}
        showPaginationTop
        pagination={{
            labelRowsPerPage: 'Filas por página:'
        }}
        actionsLabel='Acciones'
        advancedFiltersLabel="Mostrar/Ocultar filtros"
        columnsHeader={columnsHeader}
        onClick={action('clicked')}
    />;

Props

NameTypeDescription
apijsonData for fetch request, url attribute is required
actionsjsonActive actions, show and edit attribute need end point for redirect, delete is boolean
onSearchfunccallback function with row id param
onEditfunccallback function with row id param
filtersboolShow advance filters
showPaginationTopboolput paginations in top of table
paginationjsonlabelRowsPerPage attribute, label rows per page
actionsLabelstringActions Label for column header
advancedFiltersLabelstringAdvanced filters label
columnsHeaderjson{ name, label, number, filter, isPrimary, showInTable, ...rest }