Bootstrap toggle not changing in a jquery yadjra datatable and laravel
i have been able to integrate bootstrap toggle in my jquery data table perfectly.in this case it works this way,on toggling it updates the a 'status' column in the category table from 0 to 1.0 means the category is inactive and 1 means the category is active.all this works well but am having a small issue.lets say for example i have activated the user in the toggle button to active,the active button will should show as active.in mycase the button isn't showing as per the value in the status column.how can i fix this
this is my js script that shows the data in the datatable
var rentalhousescatstable = $('#rentalcatstable').DataTable({
processing:true,
serverside:true,
responsive:true,
ajax:"{{ route('get_rentalcats') }}",
columns: [
{ data: 'id' },
{ data: 'rentalcat_title' },
{ data: 'status',name:'status',orderable:false,searchable:false },
{ data: 'action',name:'action',orderable:false,searchable:false },
],
"fnDrawCallback": function( row ) {
$('.rentalcatstatus')
.prop( 'checked', row.status !== 1 )
.bootstrapToggle();
}
});
this is my code in the controller
public function get_rentalcats(Request $request)
{
$rentalcats=Rental_category::select('id','rentalcat_title','status');
Session::put('page','rental_tags');
if($request->ajax()){
$rentalcats = DataTables::of ($rentalcats)
->addColumn ('status',function($row){
return
'<input class="rentalcatstatus" type="checkbox" checked data-toggle="toggle" data-id="'.$row->id.'" data-on="Active" data-off="Not Active" data-onstyle="success" data-offstyle="danger">';
})
->addColumn ('action',function($row){
return
'<a href="#" title="Edit the cat" class="btn btn-success editrentalcat" data-id="'.$row->id.'"><i class="fas fa-edit"></i></a>
<a href="#" id="deleterentalcat" title="Delete the cat" class="btn btn-danger" data-id="'.$row->id.'"><i class="fa fa-trash"></i></a>';
})
->rawColumns(['status','action'])
->make(true);
return $rentalcats;
}
return view('Admin.Rental_houses.rentals',compact('rentalcats'));
}
Please or to participate in this conversation.