Laravel-datatables: Buttons default config overrides buttons

Created on 20 May 2020  路  6Comments  路  Source: yajra/laravel-datatables

First of all, thank you very much for this great tool. When I try to set the button defaults through html builder, class applied to the buttons but not the buttons I choose to create are created but the certain set of them are. Below are the before/after secreen shots.
Screenshot_before
Screenshot_after

Thank you.

public function html()
    {
        return $this->builder()
            ->setTableId('users-table')
            ->columns($this->getColumns())
            ->minifiedAjax()
            ->dom("<'row'<'col-sm-12'B>><'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>")
            ->orderBy(1, 'asc')
            ->parameters([
                'orderClasses' => false,
                'pagingType' => 'first_last_numbers',
                // Buttons default class
                'buttons' => [
                    'dom' => [
                        'button' => [
                            'className' => 'btn btn-outline-primary',
                        ]
                    ]
                ]
            ])
            ->stripeClasses(['alert-info', 'alert-light'])
            ->buttons(
                Button::make('create')->text('Olu艧tur'),
                Button::make('export'),
                Button::make('print'),
                Button::make('reset'),
                Button::make('reload')
            );
    }
  • Laravel Version - Latest
  • Laravel-Datatables Version - Latest

Most helpful comment

@hgokturk hi did you solve you problem?
I just face this problem also. I just solve it by using this code

/**
     * Optional method if you want to use html builder.
     *
     * @return \Yajra\DataTables\Html\Builder
     */
    public function html()
    {
        return $this->builder()
                    ->setTableId('users-table')
                    ->columns($this->getColumns())
                    ->minifiedAjax()
                    ->orderBy(1)
                    ->parameters([
                        'dom'          => 'Bfrtip',
                        'buttons'      => [
                            'buttons' => [
                                [
                                    'extend' => 'create',
                                    'text' => 'My Custom Name'
                                ], 
                                'print', 'excel'
                            ],
                            'dom' => [
                                'button' => [
                                    'className' => 'btn btn-light'
                                ]
                            ]
                        ],
                    ]);
    }

which we need to config buttons in side parameters method. this work for me. I spend 3 days to figure out and fixed it.

All 6 comments

@hgokturk hi did you solve you problem?
I just face this problem also. I just solve it by using this code

/**
     * Optional method if you want to use html builder.
     *
     * @return \Yajra\DataTables\Html\Builder
     */
    public function html()
    {
        return $this->builder()
                    ->setTableId('users-table')
                    ->columns($this->getColumns())
                    ->minifiedAjax()
                    ->orderBy(1)
                    ->parameters([
                        'dom'          => 'Bfrtip',
                        'buttons'      => [
                            'buttons' => [
                                [
                                    'extend' => 'create',
                                    'text' => 'My Custom Name'
                                ], 
                                'print', 'excel'
                            ],
                            'dom' => [
                                'button' => [
                                    'className' => 'btn btn-light'
                                ]
                            ]
                        ],
                    ]);
    }

which we need to config buttons in side parameters method. this work for me. I spend 3 days to figure out and fixed it.

Wow, I personally haven't tried that options as I usually set the defaults in javascript. Thanks for sharing your solution.

@Sok-Hai I wish I shared my solution before :)

public function html()
    {
        return $this->builder()
            ->setTableId('users-table')
            ->columns($this->getColumns())
            ->minifiedAjax()
            ->dom("<'row'<'col-sm-12 mb-4'B>><'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>><'row'<'col-sm-12'tr>><'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>")
            ->orderBy(1, 'asc')
            //->paging(false)
            ->parameters([
                'orderClasses' => false,
                //'processing' => false,
                'pagingType' => 'first_last_numbers',
                'renderer' => [
                    'header' => 'bootstrap4',
                    'pageButton' => 'bootstrap',
                ],

                // Buttons default class
                'buttons' => [
                    'buttons' => [
                        [
                            'extend' => 'excel', 'text' => 'EXCEL'
                        ],
                        [
                            'extend' => 'print', 'text' => 'PRINT'
                        ],
                        [
                            'extend' => 'reload', 'text' => 'RELOAD'
                        ],
                        [
                            'extend' => 'reset', 'text' => 'RESET'
                        ],
                    ],
                    'dom' => [
                        'button' => [
                            'className' => 'btn btn-outline-primary btn-sm',
                        ]
                    ]
                ]
            ])
            ->stripeClasses(['alert-info', 'alert-light']);
        /*->buttons(
            Button::raw([
                'extend' => 'excel',
                'text' => 'deneme'
            ]),

        Button::make('create')->text('Olu艧tur'),
        Button::make('export'),
        Button::make('print'),
        Button::make('reset'),
        Button::make('reload')
        );*/
    }

This seems the way to do it.

@hgokturk next time if you found solution and fixed it. please post so i can save my 3 days. haha

@Sok-Hai I'm really sorry :)

@hgokturk yeah. so issue should be close now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nasirkhan picture nasirkhan  路  3Comments

SGarridoDev picture SGarridoDev  路  3Comments

techguydev picture techguydev  路  3Comments

jgatringer picture jgatringer  路  3Comments

Abdulhmid picture Abdulhmid  路  3Comments