Datatable not showing properly in the laravel blade file - laravel

I'm getting one issue in the datable. I added datatable in my laravel blade file, but when I clicked on the menu (call blade file). Then it shows a normal table, but when I refresh the same page again and then it shows datatable properly. My question is when I click on the menu(call blade file), then why it is not showing datatable properly. It shows a normal table only. How to fix this.
please check imagesthis image is before refresh
this image is after refresh
and this is my blade file
#extends('backEnd.layout')
<!--page level css starts-->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css">
<!--end of page level css-->
#section('content')
<div class="padding">
<div class="box">
<div class="box-header dker">
<h3>Product List</h3>
<small>
{{ trans('backLang.home') }} /
Product List
</small>
</div>
<table class="table table-bordered" id="table" >
<thead class=" primary">
<tr >
<th class="text-center">Category</th>
<th class="text-center">Title</th>
<th class="text-center">Make</th>
<th class="text-center">Rate</th>
<th class="text-center">Status</th>
</tr>
</thead>
<tbody>
#foreach($records as $record)
<tr>
<td class="text-center">{{$record->section_title}}</td>
<td class="text-center">{{$record->title_en}}</td>
<td class="text-center">{{$record->make}}</td>
<td class="text-center">{{$record->rate}}</td>
<td class="text-center">#if($record->status != 1) Used
#else New #endif
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
#endsection
#section('footerInclude')
<script type="text/javascript">
$("#checkAll").click(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
});
$("#action").change(function () {
if (this.value == "delete") {
$("#submit_all").css("display", "none");
$("#submit_show_msg").css("display", "inline-block");
} else {
$("#submit_all").css("display", "inline-block");
$("#submit_show_msg").css("display", "none");
}
});
</script>
<script>
$(document).ready(function() {
$('#table').DataTable();
} );
</script>
<script src="//code.jquery.com/jquery-1.12.3.js"></script>
<script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
#endsection
any help will be appreciated.
Thanks in advance.

Your Blade file should be like this.
You should add script files before you write your script.
#extends('backEnd.layout')
<!--page level css starts-->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css">
<!--end of page level css-->
#section('content')
<div class="padding">
<div class="box">
<div class="box-header dker">
<h3>Product List</h3>
<small>
{{ trans('backLang.home') }} /
Product List
</small>
</div>
<table class="table table-bordered" id="table" >
<thead class=" primary">
<tr >
<th class="text-center">Category</th>
<th class="text-center">Title</th>
<th class="text-center">Make</th>
<th class="text-center">Rate</th>
<th class="text-center">Status</th>
</tr>
</thead>
<tbody>
#foreach($records as $record)
<tr>
<td class="text-center">{{$record->section_title}}</td>
<td class="text-center">{{$record->title_en}}</td>
<td class="text-center">{{$record->make}}</td>
<td class="text-center">{{$record->rate}}</td>
<td class="text-center">#if($record->status != 1) Used
#else New #endif
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
<script src="//code.jquery.com/jquery-1.12.3.js"></script>
<script src="//cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#table').DataTable();
$("#checkAll").click(function () {
$('input:checkbox').not(this).prop('checked', this.checked);
});
$("#action").change(function () {
if (this.value == "delete") {
$("#submit_all").css("display", "none");
$("#submit_show_msg").css("display", "inline-block");
} else {
$("#submit_all").css("display", "inline-block");
$("#submit_show_msg").css("display", "none");
}
});
} ;
</script>
#section('footerInclude')
#endsection

Related

Multiple Table search using one dropdown filter in datatable

I am using laravel and data table here I am using 2 data tables on the same page. Now I need to filter both at the same time using the dropdown. The dropdown filter is located outside my table. one table content revenue another one content Expense for the same account number.
I also want to subtract the total value. is like the 1st value came from 1st table total value, and 2nd value came from 2nd table then its subtract. is it possible?
Here Is My Code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" >
<link href="https://cdn.datatables.net/1.11.1/css/jquery.dataTables.min.css" rel="stylesheet">
<link href="https://cdn.datatables.net/datetime/1.1.0/css/dataTables.dateTime.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.11.0/js/jquery.dataTables.js"></script>
<title>JS Bin</title>
</head>
<body>
<div class="card">
<h4 class="text-center mt-3 mb-3"><u>Filter</u></h4>
<div class="card-body">
<div>
<div class="row">
<div class="col-sm-4">
<div class="form-group row">
<label for="staticEmail" class="col-sm-4 col-form-label text-dark">Account Number</label>
<div class="col-sm-8">
<div id="account_number"></div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group row">
<label for="staticEmail" class="col-sm-4 col-form-label text-dark">From</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="min" name="min" placeholder="mm/dd/yyyy">
</div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group row">
<label for="staticEmail" class="col-sm-4 col-form-label text-dark">To</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="max" name="max" placeholder="mm/dd/yyyy">
</div>
</div>
</div>
</div>
</div>
<div id="buttons"></div>
</div>
</div>
<div class="card">
<h4 class="text-center mt-3 mb-3"><u>Bank Statement</u></h4>
<p class="text-center" id="account_number1"></p>
<div class="card-body">
<div class="table-responsive">
<table class=" table table-borderless " style="min-width: 845px">
<thead>
<tr>
<th>Account Number</th>
<th>BAnk Name</th>
<th>Date</th>
<th>Expenses</th>
<th class="text-center">Amount</th>
</tr>
</thead>
<tbody>
<!-- #foreach (App\Models\BankTransaction::where('type','debit')->get() as $item) -->
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-07</td>
<td>Withdraw</td>
<td class="text-center">10000</td>
</tr>
<!-- #endforeach -->
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-07</td>
<td>Online Payment</td>
<td class="text-center">10000</td>
</tr>
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-07</td>
<td>Online Payment</td>
<td class="text-center">10000</td>
</tr>
<tr>
<td>54-0211-15145</td>
<td>ANC Bank</td>
<td>2021-09-05</td>
<td>Card Bill</td>
<td class="text-center">6000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Account Number</th>
<th>BAnk Name</th>
<th>Date</th>
<th>Expenses</th>
<th class="text-center">Amount</th>
</tr>
</tfoot>
</table>
<table class=" table table-borderless " style="min-width: 845px">
<thead>
<tr>
<th>Account Number</th>
<th>BAnk Name</th>
<th>Date</th>
<th>Revenues</th>
<th class="text-center">Amount</th>
</tr>
</thead>
<tbody>
<!-- #foreach (App\Models\BankTransaction::where('type','credit')->get() as $item) -->
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-06</td>
<td>Account Open</td>
<td class="text-center">1000</td>
</tr>
<!-- #endforeach -->
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-06</td>
<td>Diposit</td>
<td class="text-center">10000</td>
</tr>
<tr>
<td>35302111502</td>
<td>ABC Bank</td>
<td>2021-09-07</td>
<td>Balance Transfer</td>
<td class="text-center">10000</td>
</tr>
<tr>
<td>54-0211-15145</td>
<td>ANC Bank</td>
<td>2021-09-01</td>
<td>Account Opening</td>
<td class="text-center">1000</td>
</tr>
<tr>
<td>54-0211-15145</td>
<td>ANC Bank</td>
<td>2021-09-03</td>
<td>Diposit</td>
<td class="text-center">3000</td>
</tr>
<tr>
<td>54-0211-15145</td>
<td>ANC Bank</td>
<td>2021-09-05</td>
<td>Online Earn</td>
<td class="text-center">6000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Account Number</th>
<th>BAnk Name</th>
<th>Date</th>
<th class="text-dark"><h4>Total Revenues</h4></th>
<th class="text-dark text-center h4"></th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</body>
<script>
$(document).ready(function() {
//Date Filter Start
var minDate, maxDate;
$.fn.dataTable.ext.search.push(
function( settings, data, dataIndex ) {
var min = minDate.val();
var max = maxDate.val();
var date = new Date( data[1] );
if (
( min === null && max === null ) ||
( min === null && date <= max ) ||
( min <= date && max === null ) ||
( min <= date && date <= max )
) {
return true;
}
return false;
}
);
minDate = new DateTime($('#min'), {
format: 'MMMM Do YYYY'
});
maxDate = new DateTime($('#max'), {
format: 'MMMM Do YYYY'
});
var editor;
var table= $('table.table-borderless').DataTable({
"dom":'t',
"columnDefs": [
{
"targets": [ 1 ],
"visible": false,
"searchable": true
},
{
"targets": [ 0 ],
"visible": false,
"searchable": true
},
],
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api();
// 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;
};
amount = api
.column( 3, { search: "applied" } )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
$( api.column( 3 ).footer() ).html(
amount
);
},
initComplete: function() {
//Drop Down Account Number
var column = this.api().column(0);
var select = $('<select class="form-control" ><option value="">All Account</option></select>')
.appendTo($('#account_number').empty())
.on('change', function() {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column.search(val ? '^' + val + '$' : '', true, false).draw();
document.getElementById("account_number1").innerHTML = val;
//console.log(column);
});
column.data().unique().sort().each(function(d, j) {
select.append('<option value="' + d + '">' + d + '</option>');
});
}
});
//Date Filter
$('#min, #max').on('change', function () {
table.draw();
});
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
<script src="https://cdn.datatables.net/1.11.0/js/jquery.dataTables.js"></script>
<script src="https://cdn.datatables.net/plug-ins/1.11.0/api/sum().js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<script src="https://cdn.datatables.net/datetime/1.1.0/js/dataTables.dateTime.min.js"></script>
</html>

Assign an ID to create a "View Details" on a table to link to a view

I have a table and want to add a "View Details" button for each row which links to a further details page, I have easily added the button but am looking for a little help to be able to make it open to the specific message it's related too.
My Current View:
#extends ('layout')
#section('content')
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="/filtering.js"></script>
<link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.js"> </script>
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/fixedheader/3.1.6/js/dataTables.fixedHeader.min.js"></script>
<div class="row align-items-center">
<div class="col">
<h1>
MESSAGES R US
</h1>
</div>
<div class="col ">
CREATE MESSAGE
</div>
<div class="col ">
VIEW DETAILS
</div>
</div>
<div class="form-group"> <!-- This works-->
<table id="userTable" data-page-length='5' cellspacing="0"
class="table table-bordered table-striped table-hover table-condensed"
role="grid">
<thead>
<tr>
<th scope="col">CREATED</th>
<th scope="col">USERNAME</th>
<th scope="col">TO/FROM</th>
<th scope="col">UPDATED</th>
<th scope="col">MESSAGE ID</th>
<th scope="col">STATUS</th>
<th scope="col">ACTION</th>
</tr>
</thead>
<tbody>
#foreach ($messages as $message)
<tr>
<td>{{$message->created_at}}</td>
<td>{{$message->username}}</td>
<td class="text-center">
#if ($message->direction == 'from')
<span class='badge badge-warning'>from</span>
#else
<span class='badge badge-success'>{{$message->direction}}</span>
#endif
</td>
<td>{{$message->updated_at}}</td>
<td>{{$message->message_id}}</td>
<td class="text-center">
#if ($message->status == 'FAIL')
<span class='badge badge-danger'>FAIL</span>
#elseif ($message->status == 'received')
<span class='badge badge-info'>received</span>
#elseif ($message->status == 'delivered')
<span class='badge badge-primary'>delivered</span>
#elseif ($message->status == 'queued')
<span class='badge badge-warning'>queued</span>
#elseif ($message->status == 'read')
<span class='badge badge-success'>read</span>
#endif
</td>
</td>
<td>
<div class="col ">VIEW</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div
#endsection
I have built this in Laravel, when VIEW is clicked it just displays the same table without being specific to the message's row, I don't know how to link it to further display the MESSAGE ID details. This is a leisure project so excuse the formatting and UI. I am new to laravel with previously using ASP.NET MVC. Any help is appreciated.
I understand the concept which I need to make it work. Use the message_ID as the key for the button, then utilize that tables data (MESSAGE_ID - MESSAGE_TEXT) I just need the help to connect the dots. :)
First you have to declaration the "details route" in your route. Your route maybe will looks like this
Route::get('/message/{id}/details', 'YourController#details')->name('message.detail');
and then in your views the button will be call this route. so your Button views will be looks like
VIEW
And hen last in your controller. you must have method that you declare before in route (in my example the method name is "details").
public function details(Request $request, $id){
// your detail code here
}

How to show checkbox selected values in the same laravel view before submitting the form?

I have create.blade.php view. And that view showing a table with checkbox in each row. Now I want to show the checked row on the same view next to this table. Till now what I am getting the all the checked values but how can show it the same view before sending any post request to the server.
Here is some code-
#if(count($movies) > 0)
<div class="table-responsive">
<table class="table table-striped table-hover" data-toggle="dataTable"
data-form="deleteForm">
<thead>
<tr>
<th></th>
<th scope="col">Name</th>
</tr>
</thead>
<tbody>
<label>Select movies</label>
#foreach($movies as $movie)
<tr>
<td>
<input class="form-check" type="checkbox" name="movie_cb" id=" .
{{$movie->id}}" value="{{$movie->name}}">
</td>
<td>{{$infeedVideo->name}}</td>
</tr>
#endforeach
</tbody>
</table>
#else
<div class="text-center">
<hr>
<p class="text-center">No movies found</p>
</div>
#endif
app.blade.php
<script type="text/javascript">
$(document).ready(function() {
$("#showCBs").click(function(){
var favorite = [];
$.each($("input[name='movie_cb']:checked"), function(){
favorite.push($(this).val());
});
alert("My favourite movies are: " + favorite.join(", "));
});
});
</script>
Now how can I pass the favorite array from app.blade.php to my laravel view create.blade.php. Thank you

how to perform sorting,search,pagination in codeigniter

I'm a fresher in codeigniter. I want to search,sort and apply pagination to my table.
I tried my best.when search code is working sorting may not work. i can't perform these three actions in a single table. please help me.
use Bootstrap datatables. It has in built search, Sort and pagination too.
Sample of My code
In View
<div style="clear: both; margin-top: 35px"></div>
<div class="container">
<div class="col-sm-12" style="padding: 0px">
<div class="row">
<div class="col-sm-10 col-sm-offset-1 " style="padding-right:0px;">
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th width="20%"></th>
<th width="15%"></th>
<th width="20%"></th>
<th width="15%"></th>
<th width="10%"></th>
</tr>
</thead>
<tbody>
<?
foreach ( $ as $ )
{
?>
<tr>
<td><?php echo $['']?></td>
<td><?php echo $['']?></td>
<td><?php echo $['']?></td>
<td><?php echo $['']?></td>
</tr>
<?
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
In Controller
$data[''] = $this->model_name->function_name();
In Header
<link href="<?php echo base_url(); ?>css/bootstrap.css" rel="stylesheet" />
<link href="<?php echo base_url(); ?>css/bootstrap-glyphicons.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/plug-ins/1.10.7/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet" />
Output

Dompdf output contains weird borders

I'm currently trying to convert a HTML file into PDF file using DOMPDF. However the converted pdf files contains these red and yellow borders. Is there any way to remove these borders?
Part of my html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!--<link rel="stylesheet" href="<?php echo base_url('styles/CPP.css')?>" type="text/css" />-->
</head>
<body>
<div id="header">
<div id="logo">
<!--<img src="<?php echo base_url('styles/logo.gif')?>"/>-->
</div>
<div id="version-date">
<p>Version date: 26 Aug 2015</p>
</div>
<div id="form-title">
<p><i>Research and Consultancy Office</i></p>
<p>Graduate Studies and Research Education</p>
<p style="font-size: 25px"><strong>Conference Participation Proposal</strong></p>
</div>
</div>
<div id="info">
<p>This form will be used by Coordinating Supervisors to recommend their research students for
conference participation. File Naming Instruction for 2015. For an applicant associated with the
FECS Faculty, intending to participate in the conference CONF2015, please save the form with a
file name like this: <strong>2015</strong> FECS <strong>Student Name (</strong>CONF2015 <strong>
Participation Proposal).docx</strong></p>
</div>
<div id="form-content">
<!--<table border="1">-->
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<th class="table-title" colspan="4">STUDENT DETAILS</th>
</tr>
<tr>
<td class="align-right">Student ID</td>
<td></td>
<td class="align-right-a">Student Name</td>
<td></td>
</tr>
<tr>
<td class="align-right">Course (MBus/MSc/PhD)</td>
<td></td>
<td class="align-right-a">Date of Enrolment</td>
<td></td>
</tr>
<tr>
<td class="align-right">Research Focus or Topic</td>
<td colspan="3"></td>
</tr>
<tr>
<td class="align-right">Coordinating Supervisor</td>
<td colspan="3"></td>
</tr>
</table>
My controller:
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper('url');
require_once(APPPATH.'third_party/dompdf/dompdf_config.inc.php');
}
public function index()
{
$dompdf = new DOMPDF();
$data = "123";
$html = $this->load->view('CPP_form/Conference_Participation_Proposal.html',$data,true);
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream('CPP_Form.pdf',array('Attachment'=>0));
//$this->load->view('CPP_form/Conference_Participation_Proposal.html');
}
}
You seem to have put DOMPDF_DEBUG_LAYOUT constants to true in dompdf.config.php

Resources