Created
January 15, 2018 14:55
-
-
Save AlexMcowkin/1a289e2950b13f4edf1f384739314118 to your computer and use it in GitHub Desktop.
laravel 5.5: yajrabox datatables add html code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Backend; | |
use App\Http\Controllers\Controller; | |
use App\Model\Commondata; | |
use Illuminate\Http\Request; | |
use App\Http\Requests\CommondataRequest; | |
class CommondataController extends Controller | |
{ | |
const PERPAGE = 10; | |
public function index() | |
{ | |
$commondata = Commondata::all(); | |
return view('backend.commondata.index', compact('commondata')); | |
} | |
public function getdrid() | |
{ | |
$commondata = Commondata::query(); | |
return \DataTables::eloquent($commondata) | |
->editColumn('blocked', function($commondata){ | |
return ($commondata->blocked) ? '<i class="fa fa-check" aria-hidden="true"></i>' : '<i class="fa fa-times" aria-hidden="true"></i>'; | |
}) | |
->addColumn('multiselect', function($commondata){ | |
return '<label class="ckbox mg-b-0"><input type="checkbox" id="selectOneInTable" data-id="'.$commondata->id.'"><span></span></label>'; | |
}) | |
->rawColumns(['multiselect', 'blocked']) | |
->toJson(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('backend.layouts.common') | |
@section('meta_content') | |
<title>{{'Commondata | Admin Panel'}}</title> | |
@endsection | |
@section('breadcrumbs') | |
{{ Breadcrumbs::render('commondata.index') }} | |
@endsection | |
@section('content') | |
<div class="card pd-20 pd-sm-40"> | |
<h6 class="card-body-title">Commondata</h6> | |
<p>commondata configuration</p> | |
<div class="table-wrapper"> | |
<table id="datatable1" class="table display responsive nowrap"> | |
<thead> | |
<tr> | |
<th class="wd-10p"><label class="ckbox mg-b-0"><input type="checkbox" id="selectAllInTable"><span></span></label></th> | |
<th class="wd-30p">param</th> | |
<th class="wd-30p">value</th> | |
<th class="wd-30p">blocked</th> | |
</tr> | |
</thead> | |
</table> | |
<hr> | |
<div class="btn-group" role="group" aria-label="Basic example"> | |
<a href="{{ route('commondata.create') }}" class="btn btn-secondary pd-x-25 mg-r-5"><i class="fa fa-plus"></i> Add New/Update</a> | |
<a href="{{ route('commondata.deleteall') }}" id="deleteAllSelected" class="btn btn-secondary pd-x-25"><i class="fa fa-trash"></i> Remove Selected</a> | |
</div> | |
</div> | |
</div> | |
@endsection | |
@section('gridviewcontent') | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$('#datatable1').DataTable({ | |
responsive: true, | |
processing: true, | |
serverSide: true, | |
language: { | |
searchPlaceholder: 'Search here...', | |
sSearch: '', | |
lengthMenu: '_MENU_', | |
paginate: { | |
"previous": "Previous", | |
"next": "Next", | |
}, | |
info: "Total rows: _TOTAL_", | |
}, | |
ajax: '{{ route('commondata.getdrid') }}', | |
columns: [ | |
{data: 'multiselect', orderable: false, searchable: false}, | |
{data: 'param'}, | |
{data: 'value'}, | |
{data: 'blocked'}, | |
] | |
}); | |
$('.dataTables_length select').select2({ minimumResultsForSearch: Infinity }); | |
}); | |
</script> | |
@endsection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment