我正在使用yajra/datatables
,yajra/datatables-html
,yajra/laravel-datatables-oracle
。
我已经按照yajra / datatables-html教程中的带有“ bootstraptoogle”属性的“编辑列”进行了教程,还包括了带有CSS的js的bootstarp toogle,但是bootstarp toogle无法正常工作。
也许我遗漏了一些东西,因为如果我尝试通过Controller显示表格,我可以看到数据,但是当然不应用复选框按钮bootstrap toogle。
PHP Version: 7.1.3
Laravel Version: 5.8
Yajra/laravel-datatables Version: ^1.5
Yajra/laravel-datatables-html Version: ^4.4
Yajra/laravel-datatables-oracle Version: ^9.2
这是我的Blade文件代码
{!! $html->table(['class'=>'table table-hover datatable mdl-data-table dataTable']) !!}
这是我的控制器功能
use DataTables;
use App\Doctor;`enter code here`
use Illuminate\Http\Request;
use Yajra\DataTables\Html\Builder;
/**
* Build DataTable class.
*
*/
class AdminController extends Controller
{
public function doctor(Builder $builder)
{
if (request()->ajax()) {
$model = Doctor::query();
return DataTables::eloquent($model)
->editColumn('status', function(Doctor $doctor) {
$checkedStatus = ($doctor->status == 1) ? 'checked' : '';
return '<input type="checkbox" id="dl-admin-toggle" "'.$checkedStatus.'" data-toggle="toggle" data-on="Ready" data-off="Not Ready" data-onstyle="success" data-offstyle="danger" />';
})
->rawColumns(['status'])
->toJson();
}
$page_title = 'Doctor';
$html = $builder->columns([
['data' => 'id', 'name' => 'Id', 'title'=>'Invoice Link'],
['data' => 'name', 'name' => 'Fisrt Name', 'title'=>'First Name'],
['data' => 'status', 'name' => 'Status', 'title'=>'Status']
])->parameter([
'initComplete'=> 'function() {
$('.dl-admin-toggle').bootstrapToggle()
}
]);
return view('admin.doctor', compact('html','page_title'));
}
}