Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt rendering of the views using layouts to aid in customizability #67

Merged
merged 3 commits into from
Jun 21, 2018

Conversation

leantony
Copy link
Owner

@leantony leantony commented Jun 20, 2018

Address #57

sample layout is a bootstrap 4 card.

<div class="row laravel-grid" id="{{ $grid->getId() }}">
    <div class="col-md-12 col-xs-12 col-sm-12">
        <div class="card">
            <div class="card-header">
                <div class="pull-left">
                    <h4 class="grid-title">{{ $grid->renderTitle() }}</h4>
                </div>
                {!! $grid->renderPaginationInfoAtHeader() !!}
            </div>
            <div class="card-body">
                @yield('data')
            </div>
            <div class="card-footer">
                {!! $grid->renderPaginationInfoAtFooter() !!}
                {!! $grid->renderPaginationLinksSection() !!}
            </div>
        </div>
    </div>
</div>

The grid itself will be inserted at the data section. To customize the template, i've added an extra key to the config file

/**
     * Grid templates
     */
    'templates' => [
        /**
         * The view to use for the templates
         */
        'view' => 'leantony::grid.templates.bs4-card'
    ]

As you can see, changing the view to use for the layout should be easy. The variables in the card template are not mandatory. You can tweak the view the way you want it to be.
However, since the grid uses PJAX, you might as well ensure that you have the ID of the grid's container set. Otherwise, you'll get javascript errors. The layout should start like this;

<div class="row laravel-grid" id="{{ $grid->getId() }}">

The class laravel-grid is used to apply some preset classes to the HTML elements within the grid, so it is also needed.
You can also set this functionality per grid, by calling the withCustomTemplate function when creating your grid. Like this;

$someGrid->create(['query' => User::query(), 'request' => $request])->withCustomTemplate('view_name')

Alternatively, you can override the getRenderingTemplateToUse function. By default, it gets the view set in configuration.

/**
     * Get the rendering template/grid layout to use
     *
     * @return string
     */
    public function getRenderingTemplateToUse(): string
    {
        return $this->getGridTemplateView();
    }

Setting the view on the config file will make the layout/template apply to all grids created.

@leantony leantony added the new feature Request for a new feature label Jun 20, 2018
@leantony leantony self-assigned this Jun 20, 2018
@leantony leantony merged commit ab12418 into master Jun 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Request for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant