how to change the number of total rows in datatable - datatable

I'm developing an application with Symfony 3 in which I'm using datatables.
to avoid getting all rows of database, I'm using doctrine's paginator. so i want the datatable will get 100 elements first, then when I click in next button it will charge the next 100 elements.
My problem is that when setting datatable with first 100 elements, I can't click on next button. ( because it's showing the 100 elements so there are no other elements for it). I want to tell it that I have more than 100 elements. so how can I do it.
My table :
<table class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%"
id="table_city">
<thead>
<tr>
<th>Code</th>
<th>Name</th>
<th>Region</th>
<th>Country</th>
<th class="no-sort">Actions</th>
</tr>
</thead>
<tbody>
{% for core_city in core_cities %}
<tr>
<td>{{ core_city.code }}</td>
<td>{{ core_city }}</td>
<td>{{ core_city.CoreRegion }}</td>
<td>{{ core_city.CoreRegion.coreCountry }}</td>
<td class="datatable_td_buttons">
<a class="m-portlet__nav-link btn m-btn m-btn--icon m-btn--icon-only m-btn--pill"
title="Show" href="{{ path('core_city_show', { 'id': core_city.id }) }}">
<i class="la la-search"></i>
</a>
<a href="{{ path('core_city_edit', { 'id': core_city.id }) }}"
class="m-portlet__nav-link btn m-btn--icon m-btn--icon-only m-btn--pill" title="Edit">
<i class="la la-edit"></i>
</a>
<a href="{{ path('core_zip_code_import_by_city', { 'id': core_city.id } ) }}"
class="m-portlet__nav-link btn m-btn--icon m-btn--icon-only m-btn--pill"
title="Import Zip Code">
<i class="la la-upload"></i>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>

I found solution :
$('#example').dataTable( {
"infoCallback": function( settings, start, end, max, total, pre ) {
return start +" to "+ end;
}
} );

Related

Get tags in view blade depending on how data is cycled

I have the code shown below.
Cycle the clinics; for each response, if the clinic id corresponds to the clinic id present in the response and if the guest id corresponds to the guest id present in the response I want it to print the date of the response otherwise the button to add the response.
As I did, the code prints me how many buttons (even if the date is present) how many responses, while as I said above, I want to get the button only if the date is not present.
<table id="tabledata" class="table table-striped hover">
<thead>
<tr>
<th>Surname</th>
<th>Name</th>
<th>Phone</th>
#foreach($clinics as $clinic)
<th>{{$clinic->name}}</th>
#endforeach
</tr>
</thead>
<tbody>
#foreach ($guests as $guest)
<tr>
<td>{{ $guest->surname }}</td>
<td>{{ $guest->name }}</td>
<td> {{ $guest->phone }}</td>
#foreach($clinics as $clinic)
<td>
#foreach($guest_responses as $guest_response)
#if(($guest->id == $guest_response->guest_id) && ($clinic->id == $guest_response->clinic_id))
<p>{{$guest_response->date}}</p>
#endif
<button type="button" class="btn btn-success buttonclinic" data-bs-toggle="modal" data-bs-target="#responseModal" data-id-clinic="{{$clinic->id}}" data-id-guest="{{$guest->id}}" data-name-clinic="{{$clinic->name}}" data-surname-guest="{{ $guest->surname }}" data-name-guest="{{ $guest->name }}"><i class="fa-regular fa-plus"></i></button>
#endforeach
</td>
#endforeach
</tr>
#endforeach
</tbody>
</table>
Can anyone help me?
How about to add a flag to check a response with a date?
<td>
#php
$exist_response_date = false;
#endphp
#foreach($guest_responses as $guest_response)
#if(($guest->id == $guest_response->guest_id) && ($clinic->id == $guest_response->clinic_id))
#php
if($guest_response->date) {
$exist_response_date = true;
}
#endphp
<p>{{$guest_response->date}}</p>
#endif
#endforeach
#if(!$exist_response_date)
<button type="button" class="btn btn-success buttonclinic" data-bs-toggle="modal" data-bs-target="#responseModal" data-id-clinic="{{$clinic->id}}" data-id-guest="{{$guest->id}}" data-name-clinic="{{$clinic->name}}" data-surname-guest="{{ $guest->surname }}" data-name-guest="{{ $guest->name }}"><i class="fa-regular fa-plus"></i></button>
#endif
</td>

Laravel datatables can't create custom columns

I have two tables first one simple html with no datatables, second with datables. My purpose transform first table two datatables second. But I had two main problems Grazinimo terminas column is using laravel #if and column Veiksmai using if statemens as well how can i add those as custom columns in second table.
First table code
<table class="table table-bordered">
<thead class="bg-warning">
<th>Knygos pavadinimas</th>
<th>Miestas</th>
<th>Išdavimo data</th>
<th>Grąžinimo terminas</th>
<th>Vardas</th>
<th>Pavardė</th>
<th>Kliento nr.</th>
<th>Veiksmai</th>
</thead>
<tbody>
#foreach($paskolinimai as $p)
<input type="hidden"
value="{{ $skirtumas = \Carbon\Carbon::parse(\Carbon\Carbon::today()->toDateString())->diffInDays( \Carbon\Carbon::parse( $p->terminas),false) }}">
<tr>
<td>{{ $p->pavadinimas }}</td>
<td>{{ $p->miestas }}</td>
<td>{{ $p->isdavimo_data }}</td>
#if($p->grazinimo_data != NULL)
<td>
<strong style="color: green;">Knyga grąžinta!</strong>
</td>
#elseif($skirtumas > 0)
<td>
Liko <strong style="color: crimson;">{{ $skirtumas }}</strong> dienų.
</td>
#elseif($skirtumas < 0) <td>
<strong style="color: crimson;">Terminas praėjo!</strong>
</td>
#elseif($skirtumas = 0)
<td>
<strong style="color: crimson;">Šiandien paskutinė grąžinimo diena!</strong>
</td>
#endif
<td>{{ $p->vardas }}</td>
<td>{{ $p->pavarde }}</td>
<td>{{ $p->klientasnr }}</td>
#if($p->grazinimo_data == null)
<td><a href="{{ url('patvirtinti-grazinima-'.$p->id.'-'.$p->bookid) }}"
class="btn btn-primary">Grąžinimas</a> </td>
#else
<td>
<p class="btn btn-success">Grąžinta</p>
</td>
#endif
#endforeach
</tr>
</tbody>
</table>
Second table code
<script>
$(document).ready(function () {
var darbuotojai = $('#paskolinimai').DataTable({
processing: true,
serverSide: true,
ajax:
{
url: '{!! route('get.paskolinimai') !!}'
},
columns: [
{ data: 'pavadinimas', name: 'pavadinimas' },
{ data: 'miestas', name: 'miestas' },
{ data: 'isdavimo_data', name: 'isdavimo_data' },
{ data: 'vardas', name: 'vardas' },
{ data: 'pavarde', name: 'pavarde' },
],
'oLanguage': {
'sSearch': "Paieška:",
'sZeroRecords': "Nerasta atitinkančių įrašų",
'sLengthMenu': "Rodyti _MENU_ įrašų",
'sInfo': "Nuo _START_ iki _END_ viso _TOTAL_ įrašų",
'sProcessing': "Apdorojama...",
'sLoadingRecords': "Kraunama...",
'sInfoFiltered': " - (filtruojama iš _MAX_ įrašų)",
'oPaginate': {
'sFirst': "Pirmas",
'sLast': "Paskutinis",
'sNext': "Sekantis",
'sPrevious': "Ankstesnis"
},
},
'sDom': '<"top"lfip>rt<"bottom"p><"clear">',
});
});
</script>
<table id="paskolinimai" class="table table-bordered">
<thead class="bg-warning">
<th>Knygos pavadinimas</th>
<th>Miestas</th>
<th>Išdavimo data</th>
<th>Vardas</th>
<th>Pavardė</th>
</thead>
<tbody></tbody>
</table>
</div>
So how can i add Grazinimo terminas and veiksmai correctly to the second table
I recommend you to use this package:
https://yajrabox.com/docs/laravel-datatables/master/installation
then go to section add column:
https://yajrabox.com/docs/laravel-datatables/master/add-column
and in your code will be like that:
->addColumn('intro', function(User $user) {
if($condtion){return $result}
})

One if condition works perfectly in laravel blade but another doesn't work

I have some problem in laravel blade i have simple table and first if condition works perfectly but second doesn't work maybe some one can say where is my mistake because condition almost similar to first if ;/
<h4 style="text-align: center;">Naujausi knygų išdavimai</h4>
<div class="pagrindinis">
<table class="table table-bordered">
<thead class="bg-warning">
<th>Knygos pavadinimas</th>
<th>Miestas</th>
<th>Išdavimo data</th>
<th>Grąžinimo terminas</th>
<th>Vardas</th>
<th>Pavardė</th>
<th>Kliento nr.</th>
<th>Veiksmai</th>
</thead>
<tbody>
#foreach($paskolinimai as $p)
<input type="hidden"
value="{{ $skirtumas = \Carbon\Carbon::parse(\Carbon\Carbon::today()->toDateString())->diffInDays( \Carbon\Carbon::parse( $p->terminas),false) }}">
<tr>
<td>{{ $p->pavadinimas }}</td>
<td>{{ $p->miestas }}</td>
<td>{{ $p->isdavimo_data }}</td>
#if($p->grazinimo_data != NULL)
<td>
<strong style="color: green;">Knyga grąžinta!</strong>
</td>
#elseif($skirtumas > 0)
<td>
Liko <strong style="color: crimson;">{{ $skirtumas }}</strong> dienų.
</td>
#elseif($skirtumas < 0)
<td>
<strong style="color: crimson;">Terminas praėjo!</strong>
</td>
#elseif($skirtumas = 0)
<td>
<strong style="color: crimson;">Šiandien paskutinė grąžinimo diena!</strong>
</td>
#endif
<td>{{ $p->vardas }}</td>
<td>{{ $p->pavarde }}</td>
<td>{{ $p->klientasnr }}</td>
#if($p->grazinimo_data = null)
<td><a href="{{ url('patvirtinti-grazinima-'.$p->id.'-'.$p->bookid) }}"
class="btn btn-primary">Grąžinimas</a> </td>
#elseif($p->grazinimo_data != null)
<td>Grąžinta </td>
#endif
#endforeach
</tr>
</tbody>
</table>
</div>
You're assigning the property
Change
$p->grazinimo_data = null
to
$p->grazinimo_data === null
or
is_null($p->grazinimo_data)

print the last 5 articles in the dashboard

I would like to know how to put a list of the last 5 items in the dashboard using backpack?
I made the table
<div class="table-responsive">
<table class="table table-hover m-0 table-actions-bar">
<thead>
<tr>
<th>
<div class="btn-group dropdown">
<button type="button" class="btn btn-light btn-xs dropdown-toggle waves-effect waves-light"
data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-chevron-down"></i></button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
</th>
<th>Titolo Post</th>
<th>Data</th>
<th>Stato</th>
<th>Categria</th>
<th>Azione</th>
</tr>
</thead>
<tbody>
<tr>
<td>
</td>
<td>
<h5 class="m-0 font-weight-medium"></h5>
</td>
<td>
<i class="mdi mdi-map-marker text-primary"></i>
</td>
<td>
<i class="mdi mdi-clock-outline text-success"></i>
</td>
<td>
<i class="mdi mdi-currency-usd text-warning"></i>
</td>
<td>
<i class="mdi mdi-pencil"></i>
<i class="mdi mdi-close"></i>
</td>
</tr>
</tbody>
</table>
</div>
I made the table inside the jumbotron.blade.php then the function that prints you on screen the last 5 posts I put it here? within the dashboard method?
$recentPost : Article::orderBy('id', 'desc')>limit(5)->get()
any other solution?
This line will get you the last 5 articles.
$articles = Article::orderBy('id', 'desc')->limit(5)->get();
You need to pass it to the view. Ex:
return view('dashboard', ['articles' => $articles]);
And loop the articles on the blade file table. Ex:
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Author</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>
#foreach($articles as $article)
<tr>
<th scope="row">{{ $article->id }}</th>
<td>{{ $article->title }}</td>
<td>{{ $article->author }}</td>
<td>{{ $article->created_at }}</td>
</tr>
#endforeach
</tbody>
</table>

pagination in laravel 5.3 when count of pages = 1

I have cities table and it has 7 cities I have a view page to display these cities with 10 cities per page
Controller:
$cities = City::orderBy('id', 'desc')->paginate(10);
return view('cities.home', compact('cities'));
View:
<div class="table-responsive panel panel-sky">
<table class="table table-striped table-hover">
<tr>
<th>#</th>
<th>Name</th>
<th>Created At</th>
<th>Action</th>
</tr>
#foreach($cities as $city)
<tr id="product{{$city->id}}">
<td>{{$city->id}}</td>
<td>{{$city->name}}</td>
<td>{{ $city->created_at }}</td>
<td>
<i class="glyphicon glyphicon-edit action-icon"></i>
<a type="button" class="pointer" data-toggle="modal" data-target="#deleteModal" data-type="btn-danger" data-action="delete-product" data-id="{{ $city->id }}" data-msg="Are you sure you want to delete this city?" data-title="Confirm Deletion">
<span class='glyphicon glyphicon-remove action-icon'></span>
</a>
</td>
</tr>
#endforeach
</table>
<div>
<div class="col-md-12"><?php echo $cities->render(); ?> </div>
but the issue is the paginate render is displayed with page#1, this issue occurred in laravel5.3 and did not find in laravel5.2
If you want to render pagination in your own way, you can use paginator methods. For example, to check if there is just one page, you could try:
#if ($cities->total() > 10)
// Render pagination
#endif

Resources