【问题标题】:Laravel Yajra Datatables custom button actionLaravel Yajra Datatables 自定义按钮操作
【发布时间】:2020-04-26 23:58:09
【问题描述】:

我正在使用yajra/laravel-datatables-buttons,但找不到足够有用的文档来帮助我。

我正在使用包中的创建按钮,如下所示:

它应该将我重定向到我的路线:http://laravel.blog/admin/posts/create

但它不断将我重定向到http://laravel.blog/admin/posts/creer

它将“创造”翻译成“创造”,我不知道它为什么会这样做。我只用英语构建应用程序,从未使用法语作为路线或任何东西。

AdminPostsDatatable.php:

/**
     * Optional method if you want to use html builder.
     *
     * @return \Yajra\DataTables\Html\Builder
     */
    public function html()
    {
        return $this->builder()
                    ->setTableId('adminpostsdatatable-table')
                    ->columns($this->getColumns())
                    ->minifiedAjax()
                    ->dom('Bfrtip')
                    ->orderBy(1, 'desc')
                    ->buttons(
                        Button::make('create'),
                        Button::make('export'),
                        Button::make('print'),
                        Button::make('reset'),
                        Button::make('reload')
                    );
    }

admin.posts.index 视图:

@extends("layouts.app")

@section('content')

    <h1>Posts</h1>
    @if (session('status'))
        <div class="alert alert-success">
            {{ session('status') }}
        </div>
    @endif
    {!! $dataTable->table() !!}
@endsection

@push('scripts')
    {!! $dataTable->scripts() !!}
@endpush

路线:

|        | GET|HEAD  | admin                         | admin.                | Closure                                                                | web,auth                                             |
|        | POST      | admin/posts                   | admin.posts.store     | App\Http\Controllers\AdminPostsController@store                        | web,auth                                             |
|        | GET|HEAD  | admin/posts                   | admin.posts.index     | App\Http\Controllers\AdminPostsController@index                        | web,auth                                             |
|        | GET|HEAD  | admin/posts/create            | admin.posts.create    | App\Http\Controllers\AdminPostsController@create                       | web,auth                                             |
|        | PUT|PATCH | admin/posts/{post}            | admin.posts.update    | App\Http\Controllers\AdminPostsController@update                       | web,auth                                             |
|        | DELETE    | admin/posts/{post}            | admin.posts.destroy   | App\Http\Controllers\AdminPostsController@destroy                      | web,auth                                             |
|        | GET|HEAD  | admin/posts/{post}/edit       | admin.posts.edit      | App\Http\Controllers\AdminPostsController@edit                         | web,auth           

提前致谢。

【问题讨论】:

    标签: php laravel datatable datatables


    【解决方案1】:

    我真的不知道这是否是正确的方法,但我想出了这个解决方案:

    Button::make('create')->action("window.location = '".route('admin.posts.create')."';"),
    

    【讨论】:

      【解决方案2】:

      试试这个

               public function html()
                  {
                      return $this->builder()
                                  ->setTableId('adminpostsdatatable-table')
                                  ->columns($this->getColumns())
                                  ->minifiedAjax()
                                  ->dom('Bfrtip')
                                  ->orderBy(1, 'desc')   
                                  ->parameters([
                                  'buttons'      => 
                                   [
                                      [
                                          'text' =>'<i class="fa fa-eye"></i> ' . 'My custom button',
                                          'className' => 'My custom class'
                                      ],
                                       'csv',
                                       'excel'
                                   ],
                                    ]);
                  }
      

      如果你想要下拉收集按钮

                              'buttons'      => 
                                 [
                                   "extend"=> 'collection',
                                   "text"=> 'My Collection button',
                                   "buttons" => 
                                       [ 
                                         'csv',
                                         'excel',
                                          [                
                                              [
                                                 'text' =>'<i class="fa fa-eye"></i> ' . 'My custom button',
                                                 'className' => 'My custom class'
                                              ],
                                           ] 
                                       ]
                                 ],
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-12
        • 2011-11-15
        • 2019-03-02
        • 1970-01-01
        • 2016-03-26
        • 2016-03-07
        • 2012-11-08
        • 2019-12-15
        相关资源
        最近更新 更多