我在Laravel 5.3项目中使用数据表插件我可以显示我的所有数据,但无法实现编辑和删除如何实现。
<script>
$.noConflict();
jQuery(document).ready(function() {
$('#myTable').DataTable({
processing : true,
serverSide : true,
ajax : '{{URL::asset('data')}}',
columns :[
{data:'id',name:'id'},
{data:'prizebond_number',name:'prizebond_number'},
{data:'prizebond_location',name:'prizebond_location'},
{
mRender: function (data, type, row) {
var linkEdit='<a href="{{url('user_prizebonds.edit')}}" class="btn btn-warning btn-sm glyphicon glyphicon-edit" data-id="' + row['id'] + '">EDIT</a>';
var linkDelete='<a href="{{url('user_prizebonds.destroy')}}" class="editor_remove btn btn-danger btn-sm glyphicon glyphicon-trash" data-id="' + row["data:id"] + '">DELETE</a>';
return linkEdit + " " + linkDelete;
}
}
]
});
} );
// mycontroller code
public function data(){
$current_user_id=Auth::id();
$user_prizebonds=UserPrizebond::where('user_id', "$current_user_id")->get();
return Datatables::of($user_prizebonds)->make(true);
}
答案 0 :(得分:1)
写入您的控制器功能。像这样
return Datatables::of($user_prizebonds)->addColumn('action', function ($user_prizebonds) {
return = '<button type="button" class="btn btn-default">Default</button>';
})->make(true);
和js代码
{data: 'action', name: 'action', orderable: false, searchable: false}