Bootstrap datatable not displaying on other tabs - datatables

This is the code that I have written with laravel5, basically I'm trying to display various tables separately based on the option from the dropdown chosen, the datatable works for the first table result however does not work for the rest, correct me if I'm wrong but apprently it has something to do with the data from the first call; if the second datatable uses the same function it will see that data has already been fetched and not make the ajax call to retrieve its data. and so you will not receive data to your second(nth) datatable. Been trying to solve this for two days, I believe I'm missing something, someone please helpme in providing a solution. Thank you in advance.
#extends('app')
#section('content')
<h1 class="page-header">Reports Archive</h1>
<div class="dropdown">
<a id="drop5" href="#" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" role="button" aria-expanded="false">
Zone Options:
<span class="caret"></span>
</a>
<ul id="menu2" class="dropdown-menu" role="menu" aria-labelledby="drop5">
<?php $count = 1; ?>
#foreach ($zones as $zone)
<li role="presentation" class="{{ $count == 0 ? 'active' : '' }}">
<a role="menuitem" tabindex="-1" href="#" data-target="#zone{{ $zone->id }}"> {{ $zone->zone_name }}</a></li>
<?php $count++; ?>
#endforeach
</ul>
</div>
<div role="tabpanel">
<!-- hide the below links-->
<ul class="nav nav-tabs" style="display:none;" role="tablist" id="myTab">
<?php $count = 1; ?>
#foreach ($zones as $zone)
<li role="presentation" class="{{ $count == 0 ? 'active' : '' }}">{{ $zone->zone_name }}</li>
<?php $count++; ?>
#endforeach
</ul>
<!-- Tab panes -->
<div class="tab-content">
<?php $count = 1; ?>
#foreach ($zones as $zone)
<div role="tabpanel" class="tab-pane fade in {{ $count == 0 ? 'active' : '' }}" id="zone{{ $zone->id }}">
<div class="col-md-12">
<h2> {{ $zone->zone_name }} </h2>
<table class="table table-responsive table-hover table-bordered" id="bootstrap-table">
<thead>
<tr>
<th style="vertical-align:middle">#</th>
<th>
<div class="dropdown">
<a id="drop5" href="#" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" role="button" aria-expanded="false">
Parameter Name:
<span class="caret"></span>
</a>
<ul id="menu2" class="dropdown-menu" role="menu" aria-labelledby="drop5">
#foreach ($zone->parameter as $param)
<li role="presentation">
<a class="btn btn-link" data-collapse-group="filters" data-target="#{{ $param->id }}" data-toggle="collapse">{{ $param->parameter_name }}</a></li>
#endforeach
</ul>
</div>
</th>
<th style="vertical-align:middle">Reading Value</th>
<th style="vertical-align:middle">User</th>
<th style="vertical-align:middle">Status</th>
<th style="vertical-align:middle">Timestamp</th>
</tr>
</thead>
#forelse ($parameters as $param)
<?php $index = 1; ?>
#if ($param->zone_id == $zone->id)
<tbody id="{{ $param->id }}" class="collapse">
#foreach ($readings as $reading)
#if ($param->id == $reading->parameter_id)
<tr>
<td>{{ $index }}</td>
<td>{{ $reading->parameter->parameter_name }} </td>
<td>{{ $reading->reading_value }} </td>
<td>{{ $reading->user->name }} </td>
<td>{{ $reading->parameter->threshold->getStatus($reading->reading_value) }} </td>
<td>{{ $reading->created_at }} </td>
</tr>
<?php $index++; ?>
#endif
#endforeach
#endif
#empty
<tr><td colspan="6"><div class="alert alert-warning" role="alert" style = "margin-top: 10px"> Oops! There are no parameters to display here </div></td></tr>
</tbody>
</div>
#endforelse
</div>
</table>
</div>
</div>
<?php $count++; ?>
#endforeach
</div>
</div>
#stop
#section('scripts')
<!-- Bootstrap Based Data Table Plugin Script-->
<script src="http://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script src="js/jquery.bdt.js" type="text/javascript"></script>
<script>
$(document).ready( function () {
$('#bootstrap-table').bdt();
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36251023-1']);
_gaq.push(['_setDomainName', 'jqueryscript.net']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script>
$('.dropdown-toggle').dropdown();
</script>
#stop

Related

ascending order of data from database by Id

I am trying to learn asp.net-core, and I am stuck on trying to retieve the data from database in ascending order of database Id, my code is below but not sure why its not doing it, it does acccessnding order by page but I want all the data in ascending order by database Id, any pointers wold be great...
#model IEnumerable<Citrus.Models.Customers>
#{
ViewData["Title"] = "Index";
Pager pager = new Pager();
int pageNo = 0;
if (ViewBag.Pager !=null)
{
pager = ViewBag.Pager;
pageNo = pager.CurrentPage;
}
}
<form asp-controller="Customers" asp-action="Index">
<p>
<div class="container body-content">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label class="control-label" for="searchString"></label>
<div class="input-group">
<input class="form-control" type="text" name="searchString" placeholder="Search by company name" />
<span class="input-group-btn" name="searchString"><button class="btn btn-default btn-primary mr-1"><i class="fas fa-search"></i> Search</button></span>
#*<span asp-validation-for="searchString"></span>*#
<a class="btn btn-primary" asp-action="Create"><i class="far fa-plus-square"></i> Customer</></a>
</div>
</div>
</div>
</div>
</div>
</p>
</form>
<table class="table">
<thead>
<tr>
<th>
#Html.DisplayNameFor(model => model.Company)
</th>
<th>
#Html.DisplayNameFor(model => model.Title)
</th>
<th>
#Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
#Html.DisplayNameFor(model => model.Surname)
</th>
<th>
#Html.DisplayNameFor(model => model.Tel)
</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model.OrderByDescending(i => i.Id))
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.Company)
</td>
<td>
#Html.DisplayFor(modelItem => item.Title)
</td>
<td>
#Html.DisplayFor(modelItem => item.FirstName)
</td>
<td>
#Html.DisplayFor(modelItem => item.Surname)
</td>
<td>
#Html.DisplayFor(modelItem => item.Tel)
</td>
<td>
<a asp-action="Edit" asp-route-id="#item.Id"><i class="fas fa-edit"></i></a> |
<a asp-action="Details" asp-route-id="#item.Id"><i class="fas fa-info-circle"></i></a> |
<a asp-action="Delete" asp-route-id="#item.Id"><i class="fas fa-trash-alt"></i></a>
</td>
</tr>
}
</tbody>
</table>
<div class="container">
#if (pager.TotalPages > 0)
{
<ul class="pagination justify-content-end">
#if (pager.CurrentPage > 1)
{
<li class="page-item">
<a class="page-link" asp-controller="Customers" asp-action="Index" asp-route-pg="1">First</a>
</li>
<li>
<a class="page-link" asp-controller="Customers" asp-action="Index" asp-route-pg="#(pager.CurrentPage -1)">Previous</a>
</li>
}
#for (var pge = pager.StartPage; pge <= pager.EndPage; pge++)
{
<li class="page-item #(pge == pager.CurrentPage ? "active" : "")">
<a class="page-link" asp-controller="Customers" asp-action="Index" asp-route-pg="#pge"> #pge</a>
</li>
}
#if (pager.CurrentPage < pager.TotalPages)
{
<li class="page-item">
<a class="page-link" asp-controller="Customers" asp-action="Index" asp-route-pg="#(pager.CurrentPage + 1)">Next</a>
</li>
<li>
<a class="page-link" asp-controller="Customers" asp-action="Index" asp-route-pg="#(pager.TotalPages)">Last</a>
</li>
}
</ul>
}
</div>
Many Thank
John
You need to use OrderBy in backend,use OrderBy firstly,and then get the current page data,for example:
List<Citrus.Models.Customers> data = _context.Customers
.OrderBy(c => c.Id)
.Skip(position).Take(pageSize)
.ToList();
For details,you can refer to the official doc.

ASP.Net Core 5 Print Div Vertical Alignment Problem

I have tried various alignment settings, but nothing is making a difference. Please have a look at the far right column in the image below and notice that the price is shifted down compared with the columns to the left.
Note that this is the print preview
This is what the same table looks like on the web page when not printing.
You can see that in the web page, I have set the margin for the last column to mt-0.
Here is my code:
<div class="row">
<div class="col-4">
<button class="btn btn-primary" onclick="printDiv()">Print</button>
</div>
</div>
<div class="row" id="PrintDiv">
<div class="col-md-8 offset-2">
<div class="row d-flex">
<div class="col-8">
<p>
<h2>#ViewBag.FullName</h2>
<h4>Order History</h4>
</p>
</div>
<div class="col me-1">
<img src="#(Configuration.GetValue<string>("StorageContainerURL"))/store-logo.png" )
class="img-fluid " style="max-height:75px;width:auto" alt="Alternate Text" />
</div>
</div>
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Order ID</th>
<th>Items</th>
<th>Total</th>
</tr>
</thead>
<tbody>
#foreach (var order in Model)
{
<tr>
<td class="align-middle">#order.OrderDate.ToLocalTime().ToShortDateString()</td>
<td class="align-middle">#order.Id</td>
<td class="align-middle">
<ul style="list-style-type:none">
#foreach (var item in order.OrderItems)
{
<li>
<div class="alert alert-info" role="alert">
<span class="badge bg-success">#item.Amount</span> [#item.Price.ToString("c")] - #item.Product.Name
</div>
</li>
}
</ul>
</td>
<td class="mt-0">#order.OrderItems.Select(m => m.Product.Price * m.Amount).Sum().ToString("c")</td>
</tr>
}
</tbody>
</table>
</div>
</div>
#section Scripts{
<script type="text/javascript">
function printDiv() {
var divContents = document.getElementById("PrintDiv").innerHTML;
var a = window.open('', '', 'height=500, width=500');
a.document.write('<html>');
a.document.write('<body > <br>');
a.document.write(divContents);
a.document.write('</body></html>');
a.document.close();
a.print();
}
</script>
}
Does anyone have any suggestions to make Total column align properly with the other columns?
I figured out the problem shortly after I posted the question. I realized that the Printed Version of the page would not recognize the Bootstrap classes. So instead, I changed all columns to use inline styles for alignment.
<tbody>
#foreach (var order in Model)
{
<tr>
<td style="vertical-align:text-top">#order.OrderDate.ToLocalTime().ToShortDateString()</td>
<td style="vertical-align:text-top">#order.Id</td>
<td style="vertical-align:text-top">
<ul style="list-style-type:none">
#foreach (var item in order.OrderItems)
{
<li>
<div class="alert alert-info" role="alert">
<span class="badge bg-success">#item.Amount</span> [#item.Price.ToString("c")] - #item.Product.Name
</div>
</li>
}
</ul>
</td>
<td style="vertical-align:text-top">#order.OrderItems.Select(m => m.Product.Price * m.Amount).Sum().ToString("c")</td>
</tr>
}
</tbody>

How to replace in Laravel 8

You can see I can add numbers by doing CRUD operation in laravel
I have added 1.6 and it shows 1.6
But I want when I add 1.6 it will replace and will show one point six
This is NumberController.php
public function index()
{
$products = Product::latest()->paginate(5);
return view('products.index',compact('products'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'detail' => 'required',
]);
Product::create($request->all());
return redirect()->route('products.index')
->with('success','Product created successfully.');
}
I will add my value here
This is my create.blade.php
<form action="{{ route('products.store') }}" method="POST">
#csrf
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Name:</strong>
<input type="text" name="name" class="form-control" placeholder="Name">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Detail:</strong>
<input type="double" name="detail" class="form-control" placeholder="Detail">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12 text-center">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
I have to show replace value here
This is my index.blade.php
<table class="table table-bordered">
<tr>
<th>No</th>
<th>Name</th>
<th>Details</th>
<th width="280px">Action</th>
</tr>
#foreach ($products as $product)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $product->name }}</td>
<td>{{ $product->detail }}</td>
<td>
<form action="{{ route('products.destroy',$product->id) }}" method="POST">
<a class="btn btn-info" href="{{ route('products.show',$product->id) }}">Show</a>
<a class="btn btn-primary" href="{{ route('products.edit',$product->id) }}">Edit</a>
#csrf
#method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
#endforeach
</table>

How do I close One table row while clicking on another

I'm fetching data into the table and on clicking any table row it open a nested colspan inside table row.
I want to close previous table row if i click on another table row (Like accordion does )
This is my Vue File
{{index+1}}
{{statement.paper_quality_id.paper_quality}} -
{{statement.paper_size_id.length}} X {{statement.paper_size_id.width}} -
{{statement.paper_brand_id.paper_brand}} -
{{statement.thickness}}
{{Math.ceil((statement.in_total_before - statement.total_out_before)/500)}}
<td>
<div class="row">
<div
class="col-md-4 text-center"
>{{Math.floor((statement.total_sheets_in_range)/500)}}</div>
<div
class="col-md-4 text-center"
>{{Math.floor((statement.total_sheets_in_range)%500)}}</div>
</div>
</td>
<td>
<div class="row">
<div
class="col-md-4 text-center"
>{{Math.floor((statement.total_outward_range)/500)}}</div>
<div
class="col-md-4 text-center"
>{{Math.floor((statement.total_outward_range)%500)}}</div>
</div>
</td>
<td>
<div class="row">
<div class="col-md-4 text-center">
{{
Math.floor((((statement.in_total_before - statement.total_out_before) + (statement.total_sheets_in_range)) - statement.total_outward_range)/500)
}}
</div>
<div class="col-md-4 text-center">
{{
Math.floor((((statement.in_total_before - statement.total_out_before) + (statement.total_sheets_in_range)) - statement.total_outward_range)%500)
}}
</div>
</div>
</td>
</tr>
<tr :id="'show_'+index" style="display : none">
<td colspan="6">
<table class="table table-hover">
<tr>
<th>Date</th>
<th>Opening</th>
<th>Inward</th>
<th>Outward</th>
<th>Balance</th>
</tr>
<tr v-for="(_statement,index) in statements_details">
<td>{{_statement.date}}</td>
<td>
<div class="row">
<div
class="col-md-3 text-center"
>{{Math.ceil((_statement.opening.total_in - _statement.opening.total_out)/500)}}</div>
<div
class="col-md-3 text-center"
>{{Math.ceil((_statement.opening.total_in - _statement.opening.total_out)%500)}}</div>
</div>
</td>
<td>
<div class="row">
<div class="col-md-3 text-center">{{Math.ceil((_statement.inward)/500)}}</div>
<div class="col-md-3 text-center">{{Math.ceil((_statement.inward)%500)}}</div>
</div>
</td>
<td>
<div class="row">
<div
class="col-md-3 text-center"
>{{Math.ceil((_statement.outward)/500)}}</div>
<div
class="col-md-3 text-center"
>{{Math.ceil((_statement.outward)%500)}}</div>
</div>
</td>
<td>
<div class="row">
<div
class="col-md-3 text-center"
>{{Math.ceil((_statement.outward)/500)}}</div>
<div
class="col-md-3 text-center"
>{{Math.ceil((_statement.outward)%500)}}</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
This is my js file
PostLedgerID(e) {
e.preventDefault();
const AccountDetail = {
id: this.id,
start_date: this.start_date + ' 00:00:00.957761',
end_date: this.end_date + ' 00:00:00.957761'
}
var vm = this;
axios.post('/Statement/', AccountDetail)
.then((response) => {
console.log(response)
vm.statements = response.data;
}).catch((err) => {
console.log(err)
});
},
//Show Hide Nested Table
statementDetail(rowid, paper_id, brand_id, size_id, thickness) {
const userDetail = {
account_access_key_id: $('#ledger_id').val(),
start_date: this.start_date + ' 00:00:00.957761',
end_date: this.end_date + ' 00:00:00.957761',
paper_quality_id: paper_id,
paper_brand_id: brand_id,
paper_size_id: size_id,
thickness: thickness
}
axios.post('/StatementDetail/', userDetail)
.then((response) => {
console.log(userDetail)
$('#show_' + rowid).toggle();
this.statements_details = response.data;
}).catch((err) => {
console.log(err)
});
}

How can I share the dropdown menu definition accross multiple buttons

Each line in my table have a dropdown menu that show "Edit, Delete". If i have 100 lines in my table, i have 100 identical dropdown menus definition.
If is possible to define only one dropdown menu and use it for all my dropdown buttons? It seems to work but the dropdown menu is not shown at the right place. Is there a way to tell the dropdown menu to change his position to another one?
<a data-toggle="dropdown" href="#unique-dropdown">Button1</a>
<a data-toggle="dropdown" href="#unique-dropdown">Button2</a>
<div class="dropdown" id="unique-dropdown">
<ul class="dropdown-menu">
<li><i class="fa fa-pencil fa-fw"></i> Edit</li>
<li><i class="fa fa-trash-o fa-fw"></i> Delete</li>
</ul>
</div>
actually, you were really close to get what you wanted...
look this sample: http://jsfiddle.net/1jfe3wju/2/
html:
<a class="uniquedd" data-toggle="dropdown" aria-expanded="false" data-info="idofwhatyouwanttoeditordelete" href="#unique-dropdown">Button1</a>
<a class="uniquedd" data-toggle="dropdown" aria-expanded="false" data-info="otheridofwhatyouwanttoeditordelete" href="#unique-dropdown">Button2</a>
<div class="dropdown" id="unique-dropdown">
<ul class="dropdown-menu">
<li><i class="fa fa-pencil fa-fw"></i> Edit</li>
<li><i class="fa fa-trash-o fa-fw"></i> Delete</li>
</ul>
</div>
js:
$('.uniquedd').click(function(e) {
e.preventDefault();
var that = $(this);
var p = that.offset();
actOverWhat = that.data('info');
//change the actions of the buttons edit and delete
//check if open
isOpen = $("#unique-dropdown").hasClass('open');
if( isOpen ) {
that.dropdown('toggle');
}
$("#unique-dropdown").offset({ top: (p.top + 15), left: p.left });
});
offset is document related, so probably if the page is large won't help, but you have jquery .position();
You could use less js code. All you need to do is "Append" your class="dropdown-menu" to the class="dropdown" div each time you click an element that should show the menu.
Look at this example: https://jsfiddle.net/espriella/b4mztvnz/
$CHdropdown = $('#ColumnHeaderDropdownId');
$('.sharingdropdown').click(function(e) {
$(this).append($CHdropdown);
});
And this is the HTML sample:
<table class="table table-striped table-bordered" id="ChartContentGridId">
<thead>
<tr>
<th>
<div contenteditable style="float:left">Series 1</div>
<div class="dropdown sharingdropdown" style="float:right">
<button class="btn btn-xs btn-success dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-caret-down" aria-hidden="true"></i>
</button>
</div>
</th>
<th>
<div contenteditable style="float:left">Series 2</div>
<div class="dropdown sharingdropdown" style="float:right">
<button class="btn btn-xs btn-success dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-caret-down" aria-hidden="true"></i>
</button>
</div>
</th>
<th width="20px"></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<ul class="dropdown-menu pull-right" id="ColumnHeaderDropdownId">
<li><i class="fa fa-pencil"></i> Edit</li>
<li><i class="fa fa-times"></i> Delete</li>
</ul>