2016-12-05 168 views
0

我正在使用Yajra數據表,我有一個問題,如標題所說。點擊列編輯而不是編輯按鈕

這裏是我的控制器至今:

public function makeActionButtonsForDatatable($model) 
{ 

    if ($model->employed_type == DriverEmployedType::PARTTIME) { 

     return '<a href="' . route('parttimeavailable.create', ['driver' => $model->id]) . '" 
        class="btn btn-default btn-xs"></span>Set Parttime 
       </a> 
       <a href="' . route('driver.edit', ['driver' => $model->id]) . '" 
        class="btn btn-primary btn-xs"><span class="fa fa-pencil"></span> Edit 
       </a> 
       <a id="delBtn" data-url="'.route('driver.destroy', ['driver' => $model->id]).'" 
        data-toggle="modal" data-target=" #modalDelete" data-title="Confirmation" data-table-name="#datatable" data-message="Do you want to delete this record?" 
        class="btn btn-danger btn-xs delete" > 
        <span class="fa fa-trash-o"></span> Delete 
       </a>'; 

    } 

    switch ($model->status) { 
     default: 
      return' 
       <a href="' . route('driver.edit', ['driver' => $model->id]) . '" 
        class="btn btn-primary btn-xs"><span class="fa fa-pencil"></span> Edit 
       </a> 
       <a id="delBtn" data-url="'.route('driver.destroy', ['driver' => $model->id]).'" 
        data-toggle="modal" data-target=" #modalDelete" data-title="Confirmation" data-table-name="#datatable" data-message="Do you want to delete this record?" 
        class="btn btn-danger btn-xs delete" > 
        <span class="fa fa-trash-o"></span> Delete 
       </a> 
      '; 
      break; 
    } 
} 

public function makeDatatable($obj) { 

    return Datatables::of($obj) 
    ->addColumn('action', function ($model) { 
      return $this->makeActionButtonsForDatatable($model); 
    }) 
    ->editColumn('full_name', function($model) { 
      return '<a href="' . route('driver.edit', ['driver' => $model->full_name]) . '"</a>'; 
    }) 
    ->editColumn('employed_type', function($model){ 
     return DriverEmployedType::getString($model->employed_type); 
    }) 
    ->make(true); 
} 

這是我的數據表中的代碼至今:

$(document).ready(function(){ 
    var datatable = $('#datatable').DataTable(
    { 
     dom: "lrtip", 
     responsive: true, 
     processing: true, 
     serverSide: true, 
     bSortCellsTop: true, 
     ajax: { 
      url: "{{ route('driver.list') }}", 
      data: { '_token' : '{{csrf_token() }}'}, 
      type: 'POST', 
     }, 
     columns: [ 
     { data: 'full_name', name: 'full_name', className: 'text-center', }, 
     { data: 'mobile', name: 'mobile', className: 'text-center', }, 
     { data: 'nric', name: 'nric', className: 'text-center', }, 
     { data: 'license', name: 'license', className: 'text-center', }, 
     { data: 'employed_type', name: 'employed_type', className: 'text-center', }, 
     { data: 'action', name: 'action', className: 'text-center', orderable: false, searchable: false }, 
     ], 
    }); 
}); 

它沒有工作,也沒有顯示我的全名列。我想要的是一旦我點擊它的名字去編輯與該驅動程序ID的形式。

有什麼想法嗎?

+0

嘗試[x-editable](https://vitalets.github.io/x-editable/) –

+0

那不是我想要的。 –

回答

1

我想你錯過關閉<a>的全名欄,請嘗試以下代碼:

public function makeDatatable($obj) { 

    return Datatables::of($obj) 
    ->addColumn('action', function ($model) { 
      return $this->makeActionButtonsForDatatable($model); 
    }) 
    ->editColumn('full_name', function($model) { 
      return '<a href="' . route('driver.edit', ['driver' => $model->id]) . '">'. $model->full_name .'</a>'; 
    }) 
    ->editColumn('employed_type', function($model){ 
     return DriverEmployedType::getString($model->employed_type); 
    }) 
    ->make(true); 
} 

讓我知道,如果你仍然面臨着同樣的!

+0

它的工作原理,但帶有這樣的ID:return''. $model->full_name .''; btw非常感謝你:) –

+0

是的,我更新了我的答案。乾杯! –

相關問題