I'm creating a live report, I have data within the datatables, and I need to add additional data that is not relevant to the actual data table.
Controller
$response = json_decode($output,true);
if(!isset($response['error'])){
/**
* Key has access to AA permissions!
*/
if($request->ajax()) {
$data = Attacks::groupBy('attacker_name')
->selectRaw('count(*) as grand_total, attacker_name')
->selectRaw('count(case result when ? then 1 else null end) as hosp',['Hospitalized'])
->selectRaw('count(case result when ? then 1 else null end) as mug',['Mugged'])
->selectRaw('count(case result when ? then 1 else null end) as attack',['Attacked'])
->selectRaw('count(case result when ? then 1 else null end) as arrested',['Arrested'])
->selectRaw('count(case result when ? then 1 else null end) as lost',['Lost'])
->selectRaw('count(case result when ? then 1 else null end) as assist',['Assist'])
->selectRaw('count(case when war > 1 then 1 else null end) as wall')
->selectRaw('ROUND(SUM(respect_gain),2) as respect')
->selectRaw('ROUND(SUM(respect_loss),2) as respectlost')
->where('attacker_faction', 478)
->where('timestamp_ended', '>', $response['chain']['start'])
->orderBy('grand_total', 'DESC')
->get();
//$data['chain'] = $response;
return datatables()
->of($data)
->addIndexColumn()
->toJson();
}
//return view('chain', ['chain' => $response['chain']]);
}
Routes
Route::get('chain/list', [AttacksController::class, 'chaining'])->middleware(['auth'])->name('chain.list');
Route::get('chain', function () {
return view('chain');
})->middleware(['auth'])->name('chain');
Blade
<div class="mb-2">
<div class="w-full rounded shadow-xs">
<div id='chainInfo' class="p-0 rounded shadow bg-gray-600">
#php
//var_dump($chain);
#endphp
</div>
</div>
</div>
<div class="mb-2">
<div class="w-full rounded shadow-xs">
<div id='recipients' class="p-0 rounded shadow bg-gray-600">
<table class="stripe hover bg-gray-600 text-sm w-full" id="chaining">
<thead>
<tr class="text-xs font-semibold tracking-wide text-left text-white border-b dark:border-gray-700 bg-gray-500 dark:text-gray-400 dark:bg-gray-800">
<th class="px-4 py-3">#</th>
<th class="px-4 py-3">User</th>
<th class="px-4 py-3">Grand Total</th>
<th class="px-4 py-3">Total</th>
<th class="px-4 py-3">Lost</th>
<th class="px-4 py-3">Hosps</th>
<th class="px-4 py-3">Mugs</th>
<th class="px-4 py-3">Arrested</th>
<th class="px-4 py-3">Attacked</th>
<th class="px-4 py-3">Assists</th>
<th class="px-4 py-3">Respect gain</th>
<th class="px-4 py-3">Respect loss</th>
<th class="px-4 py-3">Wall</th>
</tr>
</thead>
<tfoot>
<tr class="text-xs font-semibold tracking-wide text-left text-white border-b dark:border-gray-700 bg-gray-500 dark:text-gray-400 dark:bg-gray-800">
<th colspan="2" style="text-align:right">Total:</th>
<th></th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<script type="text/javascript">
$(function () {
var table = $('#chaining').DataTable({
serverSide: true,
processing: true,
ajax: "{{ route('chain.list') }}",
"order": [[3, 'desc']],
createdRow: function ( row, data, index ) {
$(row).addClass('text-xs')
},
columnDefs: [
{ className: "text-right", targets: "_all" },
],
columns: [
{data: 'DT_RowIndex', name: 'DT_RowIndex'},
{data: 'attacker_name', name: 'attacker name'},
{data: 'grand_total', name: 'gtotal'},
{
data: null, // this will allow usage of full object
render: function ( data, type, full, meta ) {
return (data.hosp + data.attack + data.mug + data.arrested);
},
name: 'total'
},
{data: 'lost', name: 'lost'},
{data: 'hosp', name: 'hosp'},
{data: 'mug', name: 'mug'},
{data: 'arrested', name: 'arrested'},
{data: 'attack', name: 'attacked'},
{data: 'assist', name: 'assists'},
{data: 'respect', name: 'respect'},
{data: 'respectlost', name: 'respect lost'},
{data: 'wall', name: 'wall'},
],
footerCallback: function ( row, data, start, end, display ) {
var api = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
// Total over all pages
total = api
.column( 3 )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
$( api.column( 2 ).footer() ).html(
total
);
},
paging : false,
lengthMenu: false,
searching: false,
info: false
}).on( 'order.dt search.dt', function () {
table.column(0, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
cell.innerHTML = i+1;
} );
} ).columns.adjust();
setInterval(function () {
table.ajax.reload();
console.log('table reloaded')
}, 10000);
});
</script>
I want to be able to access $response within my blade, as well as sending data to the datatables! the response does not contain the same data as $data!
I think you can use the view compose feature in the Laravel and send extra information to the view.
You need to register a composer in the view service provider.for more information check the below page
https://laravel.com/docs/8.x/views#view-composers
Related
so I made an update to my table so the user can search the data filtered by date (year), by adding a drop down menu for the selection. I'm trying to use ajax to filter the date, but somehow I can't get it to work. May I know what is wrong with my code? Or is there another way to filter my table by date?
Blade file for the table view
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">Tabel Pekerjaan</h3>
<br>
<div class="card-tools">
<i class="fa fa-plus"></i>  Tambah Pekerjaan
</div>
<div class="col-md-2">
<select id="filter-tahun" class="form-control filter">
<option value="">Pilih Tahun</option>
#foreach ($pekerjaan as $pekerjaans)
<option value="{{$pekerjaans->id}}">{{$pekerjaans->tanggal}}</option>
#endforeach
</select>
</div>
</div>
<!-- /.card-header -->
<div class="card-body table-responsive">
<table id="tabelpekerjaan" class="table table-bordered">
<thead>
<tr>
<th style="width: 10px">No.</th>
<th>Paket Pekerjaan</th>
<th>Tanggal</th>
<th>Nama Perusahaan</th>
<th>Lokasi Pekerjaan</th>
<th>PPK</th>
<th>HPS</th>
<th>Gambar</th>
<th style="width: 120px">Aksi</th>
</tr>
</thead>
<tbody>
#php $no = 1; #endphp
#foreach ($pekerjaan as $pekerjaans)
<tr>
<td>{{$no++}}</td>
<td>{{$pekerjaans->pekerjaan}}</td>
<td>{{$pekerjaans->tanggal}}</td>
<td>{{$pekerjaans->penyedia->nama}}</td>
<td>{{$pekerjaans->lokasi}}</td>
<td>{{$pekerjaans->user->name}}</td>
<td>Rp. {{number_format($pekerjaans->hps,0,',',',')}}</td>
<td>
<img src="{{asset('gambarpekerjaan/'.$pekerjaans->gambar)}}" style="width: 100px"alt="">
</td>
<td>
#if (Auth::user()->status=='super')
Edit
Hapus
#else
Edit
#endif
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
</div>
</section>
here is the script
<script>
$(function () {
// let pekerjaan = $("#filter-tahun").val();
/*const table =*/ $('#tabelpekerjaan').DataTable({
"paging": true,
"lengthChange": true,
"searching": true,
"ordering": true,
"info": true,
"autoWidth": true,
"responsive": true,
// "ajax":{
// url: "{{url('')}}/datapekerjaan",
// type:"POST",
// data:function(d){
// d.pekerjaan = pekerjaan;
// return d
// }
// }
});
//Initialize Select2 Elements
$('.select2bs4').select2({
theme: 'bootstrap4'
})
});
#if (session()->has('message'))
toastr.success("{{session()->get('message')}}")
#endif
$('.delete').click(function(){
var idpekerjaan = $(this).attr('data-id');
var namapekerjaan = $(this).attr('data-nama');
Swal.fire({
title: 'Apakah Anda yakin?',
text: "Paket Pekerjaan "+namapekerjaan+" akan dihapus!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Ya, yakin!'
}).then((result) => {
if (result.isConfirmed) {
window.location = "/deletepekerjaan/"+idpekerjaan+""
Swal.fire(
'Dihapus!',
'Data berhasil dihapus.',
'success'
)
}
});
});
// $(".filter").on('change',function(){
// pekerjaan = $("#filter-tahun").val()
// table.ajax.reload(null,false)
// })
</script>
I commented on the ajax's part since it doesn't work at all and my table become a mess...
May I know how to resolve this problem? Thank in advance
Check This
$(document).ready(function () {
// Setup - add a text input to each footer cell
$('#example thead tr')
.clone(true)
.addClass('filters')
.appendTo('#example thead');
var table = $('#example').DataTable({
orderCellsTop: true,
fixedHeader: true,
initComplete: function () {
var api = this.api();
// For each column
api
.columns()
.eq(0)
.each(function (colIdx) {
// Set the header cell to contain the input element
var cell = $('.filters th').eq(
$(api.column(colIdx).header()).index()
);
var title = $(cell).text();
$(cell).html('<input type="text" placeholder="' + title + '" />');
// On every keypress in this input
$(
'input',
$('.filters th').eq($(api.column(colIdx).header()).index())
)
.off('keyup change')
.on('change', function (e) {
// Get the search value
$(this).attr('title', $(this).val());
var regexr = '({search})'; //$(this).parents('th').find('select').val();
var cursorPosition = this.selectionStart;
// Search the column for that value
api
.column(colIdx)
.search(
this.value != ''
? regexr.replace('{search}', '(((' + this.value + ')))')
: '',
this.value != '',
this.value == ''
)
.draw();
})
.on('keyup', function (e) {
e.stopPropagation();
$(this).trigger('change');
$(this)
.focus()[0]
.setSelectionRange(cursorPosition, cursorPosition);
});
});
},
}); });
Refer This https://datatables.net/extensions/fixedheader/examples/options/columnFiltering.html
I use this component in my project: yajra/laravel-datatables
I have controller:
public function dataTable(Request $request)
{
if ($request->ajax()) {
return Datatables::of($this->model->all())
->addIndexColumn()
->editColumn('enable', function ($row) {
if ($row->enable == 1)
return '<span class="label font-weight-bold label-lg label-light-success label-inline">aktywny</span>';
else return '<span class="label font-weight-bold label-lg label-light-danger label-inline">nieaktywny</span>';
})
->editColumn('name', function ($row) {
return Str::limit($row->name, 80, '...');
})
->addColumn('action', function ($row) {
$btn = '<i class="far fa-edit"></i> ';
$btn .= '<i class="removeItem far fa-trash-alt"></i> ';
return $btn;
})
->rawColumns(['action'])
->make(true);
}
}
and html:
<table class="table table-bordered data-table ">
<thead>
<tr class="resources">
<th>ID</th>
<th>Nazwa produktu</th>
<th>Status</th>
<th width="100px" class="text-center">Akcja</th>
</tr>
</thead>
<tbody class="data-table-center">
</tbody>
</table>
</div>
<div class="datatable datatable-bordered datatable-head-custom" id="kt_datatable"></div>
$(function () {
var table = $('.data-table').DataTable({
processing: true,
serverSide: true,
ajax: "{{ route('product.dataTable') }}",
language: {
url: "{{ asset('js/lang/Polish.json') }}"
},
iDisplayLength: 50,
render: function (data, type, row) {
return data;
},
columns: [
{data: 'DT_RowIndex', name: 'DT_RowIndex'},
// {data: 'id', name: 'id'},
{data: 'name', name: 'name'},
{data: 'enable', name: 'enable'},
{data: 'action', name: 'action', orderable: false, searchable: false},
]
});
});
In the status (enable) column I see this html instead of the final string. As if a blade would replace such html badly.
My result:
<span class="label font-weight-bold label-lg label-light-success label-inline">aktywny</span>
Prview: https://ibb.co/6tXdH65
How can I fix it?
just add enable in your action in dataTable function
->rawColumns(['action','enable'])
->make(true);
I am working on old laravel project and I have to modify existing one. So I am now trying to understand the code. The project is on laravel and yajra datatable. I can't understand how the destroy function work ? In the view there is a no call for destroy function but when I click the delete button still it is working.
Controller
public function loadSizes()
{
$sizes = Size::select(['id', 'name', 'code'])->get();
return DataTables::of($sizes)
->addColumn('action', function ($size) {
return '<i class="fa fa-wrench" aria-hidden="true"></i>
<button type="button" data-id="' . $size->id . '" class="btn btn-default remove-size remove-btn" data-toggle="tooltip" data-placement="top" title="Delete"><i class="fas fa-trash-alt" aria-hidden="true"></i></button>';
})
->rawColumns(['action'])
->make(true);
}
public function destory(Request $request)
{
$result = Size::where('id', $request->input('size_id'))->delete();
if ($result) {
return "SUCCESS";
} else {
return "FAIL";
}
}
view
#extends('layouts.sidebar')
#section('content')
<div class="row">
<div class="col-sm-12 pad-main">
<div class="row">
<div class="col-md-6">
<h4 class="cat-name"> Size List</h4>
</div>
</div>
<div class="row">
<div class="col-md-12 table-responsive pad-tbl">
<table class="table table-striped" id="size_table">
<thead>
<tr>
<th scope="col"> Name</th>
<th scope="col"> Code</th>
<th scope="col"> Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
#if (Session::has('action'))
#if (Session::get('action') == "create")
#if (Session::has('status_success'))
<script > showAlert("SUCCESS", "Size creation successful");</script >
#elseif(Session::has('status_error')))
<script > showAlert("FAIL", "Size creation fail");</script >
#endif
#elseif(Session::get('action') == "update")
#if (Session::has('status_success'))
<script > showAlert("SUCCESS", "Size update successful");</script >
#elseif(Session::has('status_error')))
<script > showAlert("FAIL", "Size update fail");</script >
#endif
#endif
#endif
<script>
$(document).ready(function () {
$('#size_table').DataTable({
language: {
searchPlaceholder: "Search records"
},
"columnDefs": [
{"className": "dt-center", "targets": "_all"}
],
processing: true,
serverSide: true,
ajax: '{!! url(' / load - sizes') !!}',
columns: [
{data: 'name', name: 'name'},
{data: 'code', name: 'code'},
{data: 'action', name: 'action'},
]
});
});
$(document.body).on("click", ".remove-size", function () {
var size_id = $(this).data('id');
showConfirm("DELETE", "Do you want to delete this Size ?", "deleteSize(" + size_id + ")");
});
function deleteSize(id) {
$.ajax({
type: 'get',
url: '{!! url('delete-size') !!}',
data: {size_id: id},
success: function (data) {
if (data == "SUCCESS") {
$('[data-id="' + id + '"]').closest('tr').remove();
showAlert("SUCCESS", "Delete Size successful");
}
}, error: function (data) {
showAlert("FAIL", "Delete Size fail");
}
});
}
</script>
#endsection
At the bottom of the blade view there is an AJAX in function destory(id).
That AJAX is sending a GET request to a URL delete-size with size id.
Now, if you search your web.php file for that URL (location - routes/web.php), you'll find something like this:
Route::get('delete-size', 'SizeController#destory');
This route would be sending the size id to your destory function, which is in turn searching the Size in your DB and deleting it.
// Controller
public function destroy($id)
{
Tag::find($id)->delete();
Toastr::success('Tag Successfully Deleted',"Success");
return redirect()->back();
}
// Route
Route::group(['as'=>'admin.','prefix'=>'admin','namespace'=>'Admin','middleware'=>['auth','admin']], function (){
Route::resource('tag','TagController');
});
// HTML file
<form id="delete-form-{{ $tag->id }}" action="{{ route('admin.tag.destroy',$tag->id) }}" method="POST" style="display: none;">
#csrf
#method('DELETE')
</form>
I'm in the beginning of learning laravel and vue-js, so this is rather difficult to me. I want to make a component in vue-js with a table, with sorting and pagination.
When I started the project I only used Laravel and jquery, so now I'm turning to vue js and it's getting complicated. What I have is this:
In my index.blade.php
#extends('layouts.dashboard')
#section('content')
<div class="container">
<div class="row">
<div class="col">
<table class="table">
<thead>
<tr>
<th> #sortablelink('first_name','First name') </th>
<th> #sortablelink('last_name', 'Last name') </th>
<th> #sortablelink('email', 'E-mail address') </th>
<th> #sortablelink('created_at', 'Creation date') </th>
<th></th>
</tr>
</thead>
<tbody is="submissions"></tbody>
</table>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
{{ $submissions->appends(\Request::except('page'))->render() }}
<div class="total-submissions">
Total submissions:
{{ $submissions->firstItem() }}-{{ $submissions->lastItem() }} of {{ \App\Submission::count() }}
</div>
</div>
</div>
</div>
#stop
In my component Submissions.vue:
<template>
<tbody>
<tr v-for="submission in submissions" :key="submission.id">
<td> {{submission.first_name}}</td>
<td> {{submission.last_name}} </td>
<td> {{submission.email}} </td>
<td> {{submission.created_at}} </td>
<td>
<a class="btn btn-default btn-primary" id="btn-view"
:href="'/dashboard/submissions/' + submission.id">View</a>
<a class="btn btn-default btn-primary"
id="btn-delete"
:href="'/dashboard/submissions'"
#click.prevent="deleteSubmission(submission)">Delete</a>
<label class="switch">
<input class="slider-read" name="is_read"
v-model="submission.is_checked"
#change="updateCheckbox(submission)"
type="checkbox">
<span class="slider round"></span>
</label>
</td>
</tr>
</tbody>
</template>
<script>
import qs from 'qs';
import axios from 'axios';
export default {
data: function () {
return {
submissions: [],
}
},
beforeCreate() {
},
created() {
},
mounted() {
this.fetch();
},
methods: {
fetch: function () {
let loader = this.$loading.show();
var queryString = window.location.search;
if (queryString.charAt(0) === '?')
queryString = queryString.slice(1);
var args = window._.defaults(qs.parse(queryString), {
page: 1,
sort: 'id',
order: 'asc'
});
window.axios.get('/api/submissions?' + qs.stringify(args)).then((response) => {
loader.hide();
this.submissions = response.data.data
});
},
deleteSubmission(submission) {
this.$dialog.confirm("Are you sure you want to delete this record?", {
loader: true
})
.then((dialog) => {
axios.delete('api/submissions/' + submission.id)
.then((res) => {
this.fetch()
})
.catch((err) => console.error(err));
setTimeout(() => {
console.log('Delete action completed');
swal({
title: "Update Completed!",
text: "",
icon: "success",
});
dialog.close();
}, 1000);
})
.catch(() => {
console.log('Delete aborted');
});
},
updateCheckbox(submission)
{
this.$dialog.confirm("Are you sure?", {
loader: true
})
.then((dialog) => {
axios.put('/api/submissions/' + submission.id, submission,
)
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
setTimeout(() => {
console.log('Action completed');
dialog.close();
swal({
title: "Update Completed!",
text: "",
icon: "success",
});
}, 0);
})
.catch(() => {
submission.is_checked === false ? submission.is_checked = true : submission.is_checked = false;
console.log('Aborted');
});
},
}
}
</script>
Now what I want to accomplish: Put everything in the component, but since I have php in the table to sort everything how can I do this in vue? I'm trying with bootstrap vue tables, but I'm not sure if I can display data like this. Thanks in advance.
I'm trying to hide the records fetched from my database based on their value if its 0 or 1, its displaying all records i just want to display the ones with value 1, I'm using Laravel 5.2 with Yajra/Datatables.
this is my controller:
public function get() {
if(!access()->allow('customers.read')) {
return redirect()->route('admin.dashboard')->withFlashDanger(trans('customers.general.messages.denied'));
} else {
$customers = Customer::select(array(
'id', 'code', 'name', 'rnc', 'ced', 'phone', 'email', 'active'
));
return Datatables::of($customers->get('status'), $customers->get('trashed'))
->addColumn('actions', function($customers) {
return $customers->action_buttons;
})->addColumn('check', '<input type="checkbox" name="selected_users[]" value="{{ $id }}">')
->make(true);
}
}
This is my view:
#extends('backend.layouts.master')
#section('title', app_name() . ' | ' . trans('customers.general.customers_title'))
#section('after-styles-end')
{{ Html::style("css/backend/plugin/datatables/dataTables.bootstrap.min.css") }}
#stop
#section('page-header')
<h1>
{{ trans('customers.general.customers_title') }} <small>- {{ trans('customers.general.general') }}</small>
</h1>
#endsection
#section('content')
<div class="box box-success">
<div class="box-header with-border">
<h3 class="box-title">{{ trans('customers.general.customers_list') }}</h3>
<div class="box-tools pull-right">
{{ trans('customers.general.buttons.new_customer') }}
</div>
</div><!-- /.box-header -->
<!-- Begins Customers Page -->
<div class="box-body">
<div class="table-responsive">
<table id="customers-table" class="table table-condensed table-hover">
<thead>
<tr>
<th><input type="checkbox" name="select_all" value="1" id="example-select-all"></th>
<th class="">{{ trans('customers.general.table.code') }}</th>
<th class="">{{ trans('customers.general.table.business_name') }}</th>
<th class="">{{ trans('customers.general.table.document') }}</th>
<th class="">{{ trans('customers.general.table.phone') }}</th>
<th class="">{{ trans('customers.general.buttons.email') }}</th>
<th>{{ trans('labels.general.actions') }}</th>
</tr>
</thead>
</table>
</div><!--table-responsive-->
</div><!-- /.box-body -->
</div><!--box-->
#endsection
#section('after-scripts-end')
{{ Html::script("js/backend/plugin/datatables/jquery.dataTables.min.js") }}
{{ Html::script("js/backend/plugin/datatables/dataTables.bootstrap.min.js") }}
<script>
$(document).ready(function() {
var table = $('#customers-table').DataTable({
processing: true,
serverSide: true,
ajax: {
url: '{{ route("admin.customers.get") }}',
type: 'get',
data: {active: 1}
},
columns: [
{data: 'check', name: 'check', orderable: false, searchable: false},
{data: 'code', name: 'code'},
{data: 'name', name: 'name'},
{data: 'rnc', name: 'rnc'},
{data: 'phone', name: 'phone'},
{data: 'email', name: 'email'},
{data: 'actions', name: 'actions', orderable: false, searchable: false}
],
'columnDefs': [{
'targets': 0,
'searchable':false,
'orderable':false,
'className': 'dt-body-center',
'render': function (data, type, full, meta){
return '<input type="checkbox" name="id[]" value="' + $('<div/>').text(data).html() + '">';
}
}],
"iDisplayLength": 10,
"aLengthMenu": [
[10, 20, 30, 60, -1],
[10, 20, 30, 60, "{{ trans('strings.backend.general.table.all') }}"]
],
language: {
"sProcessing": "{{ trans('strings.backend.general.table.processing') }}",
"sSearchPlaceholder": "{{ trans('strings.backend.general.search_placeholder') }}",
"search": "",
"lengthMenu": "{{ trans('strings.backend.general.table.show') }} _MENU_ {{ trans('strings.backend.general.table.records_by_page') }}",
"zeroRecords": "{{ trans('strings.backend.general.table.no_results') }}",
"info": "{{ trans('strings.backend.general.table.showing_page') }} _PAGE_ {{ trans('strings.backend.general.table.of') }} _PAGES_",
"infoEmpty": "{{ trans('strings.backend.general.table.empty') }}",
"infoFiltered": "({{ trans('strings.backend.general.table.filtered_of') }} _MAX_ {{ trans('strings.backend.general.table.total_records') }})",
"sInfo": "{{ trans('strings.backend.general.table.showing_from') }} _START_ {{ trans('strings.backend.general.table.to') }} _END_ {{ trans('strings.backend.general.table.of') }} _TOTAL_ {{ trans('strings.backend.general.table.records') }}",
"paginate": {
"previous": "{{ trans('strings.backend.general.table.previous') }}",
"next": "{{ trans('strings.backend.general.table.next') }}"
}
},
order: [[0, "asc"]],
searchDelay: 500
});
// Handle click on "Select all" control
$('#example-select-all').on('click', function(){
// Get all rows with search applied
var rows = table.rows({ 'search': 'applied' }).nodes();
// Check/uncheck checkboxes for all rows in the table
$('input[type="checkbox"]', rows).prop('checked', this.checked);
});
// Handle click on checkbox to set state of "Select all" control
$('#example tbody').on('change', 'input[type="checkbox"]', function(){
// If checkbox is not checked
if(!this.checked){
var el = $('#example-select-all').get(0);
// If "Select all" control is checked and has 'indeterminate' property
if(el && el.checked && ('indeterminate' in el)){
// Set visual state of "Select all" control
// as 'indeterminate'
el.indeterminate = true;
}
}
});
// Handle form submission event
$('#frm-example').on('submit', function(e){
var form = this;
// Iterate over all checkboxes in the table
table.$('input[type="checkbox"]').each(function(){
// If checkbox doesn't exist in DOM
if(!$.contains(document, this)){
// If checkbox is checked
if(this.checked){
// Create a hidden element
$(form).append(
$('<input>')
.attr('type', 'hidden')
.attr('name', this.name)
.val(this.value)
);
}
}
});
});
});
</script>
#stop
in my view im retreiving all the results but its also showing the ones that i have disabled with value 1, i just want to show the ones with value 0 in the list, any help would be really appreciated.
thanks all
You can use scopes or global scopes in your model, so those records are not retrieved at all.
In your model:
public function apply(Builder $builder, Model $model)
{
return $builder->where('parameter', 1);
}
This will return only the records where the parameter = 1.