Bootstrap Table GET JSON Data - ruby-on-rails

So I am trying to make bootstrap table with search and sorting with the data coming from a GET calll
<table id="example" class="table table-bordered table-striped table-hover" data-search="true">
<thead>
<tr class="text-white clickable-row" bgcolor="#578ebe" >
<th id="white-text"> # </th>
<th id="white-text"> Name </th>
<th id="white-text"> DBA </th>
<th id="white-text"> Facility ID </th>
<th id="white-text"> Active </th>
</tr>
</thead>
<tbody>
<tr ng-repeat="hospital in hospital_filtered = hospitals">
<td> <a ng-click="click(hospital)"> {{ hospital.hospital_id }} </td>
<td> <a ng-click="click(hospital)"> {{ hospital.hospital_name }} </td>
<td> <a ng-click="click(hospital)"> {{ hospital.hospital_dba }} </td>
<td> <a ng-click="click(hospital)"> {{ hospital.facility_id }} </td>
<td> <a ng-click="click(hospital)"> {{ hospital.active_flag }} </td>
</tr>
</tbody>
</table>
Here is where I make the GET call from my API. The data is coming in, but the bootstrap table sorting and sort are not working. How do I populate bootstrap table with this call?
$http.get("/hospitals/all", {
params: {authtoken: $rootScope.auth_token}}
)
.then(function(response) {
// Request completed successfully
//console.log(response);
$scope.hospitals=response.data
}, function(x) {
// Request error
console.log("Error");
});
});

You're correctly fetching the data, but the iteration is wrong.
HTML:
<input ng-model="searchKeyword" type="text">
<table id="example" class="table table-bordered table-striped table-hover" data-search="true">
<thead>
<tr class="text-white clickable-row" bgcolor="#578ebe" >
<th id="white-text" ng-click="changeSort('hospital_id')"> # </th>
<th id="white-text" ng-click="changeSort('hospital_name')"> Name </th>
<th id="white-text" ng-click="changeSort('hospital_dba')"> DBA </th>
<th id="white-text" ng-click="changeSort('facility_id')"> Facility ID </th>
<th id="white-text" ng-click="changeSort('active_flag')"> Active </th>
</tr>
</thead>
<tbody>
<tr ng-repeat="hospital in hospitals | filter: searchKeyword | orderBy: orderKeyword">
<td> <a ng-click="click(hospital)"> {{ hospital.hospital_id }} </td>
<td> <a ng-click="click(hospital)"> {{ hospital.hospital_name }} </td>
<td> <a ng-click="click(hospital)"> {{ hospital.hospital_dba }} </td>
<td> <a ng-click="click(hospital)"> {{ hospital.facility_id }} </td>
<td> <a ng-click="click(hospital)"> {{ hospital.active_flag }} </td>
</tr>
</tbody>
</table>
The Javascript part:
$scope.orderKeyword = 'hospital_name';
$scope.changeSort = function(sortAttr) {
$scope.orderKeyword = sortAttr;
};
filter: searchKeyword will use the keyword typed into the additional input-field. This way you can basically "search" the table. The results that are left will then be ordered by (orderBy) the attribute-name that's stored inside $scope.orderKeyword. I initialized it with hospital_name.
You may add additional logic like how strict the filtering and which direction the sorting is supposed to be.
Here's the documentation for the two filters in question:
https://docs.angularjs.org/api/ng/filter/orderBy
https://docs.angularjs.org/api/ng/filter/filter

Related

Why is <tfoot> only shows in the last page when printing?

I am trying to print a html using dompdf and I am trying to add a footer but the footer only shows only the last page in print view? Is it a chrome bug?
<table class="table table-bordered" cellspacing="0" style="color:black">
<thead>
<tr>
<th scope="col" style="border-top: color: white; border-left: color: white;border-right: color: white;" colspan="4"> </th>
</tr>
<tr class="text-center">
<th scope="col" class="align-middle" ></th>
<th scope="col" class="align-middle text-nowrap">Reference No.: BatStateU-FO-ESO-01</th>
<th scope="col" class="align-middle text-nowrap">Effectivity Date: January 3, 2017</th>
<th scope="col" class="align-middle text-nowrap">Revision No.: 00</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="4">
<p class="title-tab"><input type="checkbox" style=" transform : scale(2);"> Extension Service / Training is requested by clients.</p> <br>
<p class="title-tab"><input type="checkbox" style=" transform : scale(2);" checked> Extension Service / Training is Department’s initiative.</p>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<th scope="col" colspan="4"> </th>
</tr>
</tfoot>
</table>

How to remove extra/excess header from bootstrap table?

<div class="col-md-5">
<div class="card border-0 shadow">
<div class="card-body ">
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th style="text-align:center;">
#Html.DisplayNameFor(model => model.Barangay)
</th>
<th style="text-align:center;">
#Html.DisplayNameFor(model => model.Confirmed)
</th>
<th style="text-align:center;">
#Html.DisplayNameFor(model => model.PUI)
</th>
<th style="text-align:center;">
#Html.DisplayNameFor(model => model.PUM)
</th>
<th></th>
</tr>
</thead>
#foreach (var item in Model)
{
<tr>
<td>
#Html.DisplayFor(modelItem => item.Barangay)
</td>
<td style="text-align:center;">
#Html.DisplayFor(modelItem => item.Confirmed)
</td>
<td style="text-align:center;">
#Html.DisplayFor(modelItem => item.PUI)
</td>
<td style="text-align:center;">
#Html.DisplayFor(modelItem => item.PUM)
</td>
</tr>
}
</table>
</div>
</div>
</div>
</div>
I can't remove it although I tried using different styles of table.
Sorry for this dumb question for I am new to web development and ASP.Net MVC.
Please see image below for reference.
Thanks in advance for any help.
https://i.stack.imgur.com/LosFA.png
This is because you have an extra th tag in your code:
<th style="text-align:center;">
Html.DisplayNameFor(model => model.PUM)
</th>
<th></th> <!------------------delete this->
if your table have 5 head table columns and your table body have 4, the body expect 1 column and keeps the space

The DataTables are not responsive and taking too long to load the data?

I have 1000 records and I am able to fetch them from database like in one second. But they are taking like 9s for rendering. It is maybe because of data tables or I am looping through each record to display. If I disable the data tables performance is better but still not good. Following is my code, could you give your suggestions. I am pretty sure it is slow because of rendering and scripting.
<div class="table-responsive">
<table class="display" id="list" cellspacing="0">
<thead>
<tr>
<th>
#Content.Code
</th>
<th> #Content.Name </th>
<th>
#Content.Location
</th>
<th>
#Content.Date
</th>
<th> #Content.Remaining </th>
<th>
#Content.Status
</th>
<th>
</th>
</tr>
</thead>
<tbody>
#foreach (var item in Model)
{
<tr>
<td>
#item.Code
</td>
<td>
#item.Name
</td>
<td>
#item.Location
</td>
<td>
#item.Date
</td>
<td>
#item.ReDays
</td>
<td>
#item.Status
</td>
<td width="15%">
<i class="fa fa-pencil" aria-hidden="true"></i>
#if (User.IsInRole("Admin") || ViewBag.HavePermission == true)
{
<i class="fa fa-trash" aria-hidden="true"></i>
}
</td>
</tr>
}
</tbody>
</table>
</div>
I don't want to use server-side processing because I don't know how to control this HavePermisson and UserRole part. Please, give a suggestion?

How come Thymeleaf tables creates a gap?

Why does my Thyme leaf creates such a big gap when I use the following code below.
BAD/WARNING
</h3>
<h3>
APPLICATION PROCESSING
</h3>
<table class="tablebad">
<tr>
<th> Status </th>
<th> HostName </th>
<th> Process Name </th>
<th> Process Count </th>
</tr>
<tr th:each="DartModel, iterStat : ${countlist}">
<td th:if ="${DartModel.Status == 'BAD'}" th:text="${DartModel.Status}"></td>
<td th:if="${DartModel.Status == 'BAD'}" th:text="${DartModel.host}"></td>
<td th:if="${DartModel.Status == 'BAD'}" th:text="${DartModel.processName}"></td>
<td th:if="${DartModel.Status == 'BAD'}" th:text="${DartModel.processCount}"></td>
</tr>
</table>
<h3>
APPLICATION PROCESSING
</h3>
<table class="tableok">
<thead>
<tr>
<th> Status </th>
<th> HostName </th>
<th> Process Name </th>
<th> Process Count </th>
</tr>
</thead>
<tbody>
<tr th:each="DartModel, iterStat : ${countlist}">
<td th:if="${DartModel.Status == 'OK'}" th:text ="${DartModel.Status}"></td>
<td th:if="${DartModel.Status == 'OK'}" th:text="${DartModel.host}"></td>
<td th:if="${DartModel.Status == 'OK'}" th:text="${DartModel.processName}"></td>
<td th:if="${DartModel.Status == 'OK'}" th:text="${DartModel.processCount}"></td>
</tr>
</tbody>
</table>
Result
and under this will be all my data printed out with the status of "OK". I am ultimately trying to sort the data based on value. I tried working with javascript/jquery but it was too complicated. I found a way to split the data rows based on values. If values is "BAD" display table above vice versa to values with "OK"
Am I doing this wrong? I
The problem is that your are putting the th:if on the <td> elements instead of the <tr>. This means that your html looks something like this (where you have several empty rows between each non-empty row.
<table>
<tr>
<td>BAD</td>
<td>...</td>
<td>...</td>
</tr>
<tr></tr>
<tr></tr>
<tr>
<td>BAD</td>
<td>...</td>
<td>...</td>
</tr>
<tr></tr>
</table>
You should just move the th:if to the <tr> element, like so:
<table class="tablebad">
<tr>
<th>Status</th>
<th>HostName</th>
<th>Process Name</th>
<th>Process Count</th>
</tr>
<tr th:each="DartModel, iterStat : ${countlist}" th:if="${DartModel.Status == 'BAD'}">
<td th:text="${DartModel.Status}" />
<td th:text="${DartModel.host}" />
<td th:text="${DartModel.processName}" />
<td th:text="${DartModel.processCount}" />
</tr>
</table>

PHP foreach loop and separate rows with a field that has the same value

I have a database table that has a field in the row of which can have the same value. This is a "transaction id" field that will have the order number. The rows can have the same order number but different product id's for each item ordered.
I'm querying the database just fine and outputting the data as well. However, I want to separate the transaction id's that are the same and do something different with that data. I just can figure out how to do that for some reason.
example:
ID txn_id product_id Product_name field5
-------- --------- ----------- --------- ---------
1 265 98 Product Name
2 265 99 Product Name
3 244 98 Product Name
UPDATE
So here is my updated code that still needs help. I have two queries going now. One that checks for duplicates and places them into an array, then the other that loops through the database table with an if statement which checks for matching transaction id numbers.
First Query:
$myquery = $wpdb->get_results("SELECT txn_id , COUNT(*) FROM test_table HAVING COUNT(*) > 1");
global $TXN;
foreach($myquery as $query){
$TXN= $query->txn_id;
}
Then in the main query/loop
global $wpdb;
$prepare_query = $wpdb->get_results("SELECT * FROM test_table" );
foreach($prepare_query as $data){
$txn_id = $data->txn_id;
$product_id = $data->product_id;
$product_name = $data->product_name;
?>
<table class="shop_table my_account_orders" width="100%">
<thead>
<tr>
<th align="left">Order #</th>
<th align="left">Product ID</th>
<th align="left">Product Name</th>
</tr>
</thead>
<tbody>
<tr class="order">
<td>
<?php echo "#" .$txn_id; ?>
<?php
if($txn_id === $TXN){
echo'YES';
}
?>
</td>
<td>
<?php echo $product_id; ?>
</td>
<td>
<?php echo $product_name; ?>
</td>
</tr>
</tbody>
</table>
<?php } ?>
This will output:
<table width="100%">
<thead>
<tr>
<th align="left">Order #</th>
<th align="left">Product ID</th>
<th align="left">Product Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>#265 YES</td>
<td>98</td>
<td>Product Name</td>
</tr>
</tbody>
</table>
<table width="100%">
<thead>
<tr>
<th align="left">Order #</th>
<th align="left">Product ID</th>
<th align="left">Product Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>#265 YES</td>
<td>99</td>
<td>Product Name</td>
</tr>
</tbody>
</table>
<table width="100%">
<thead>
<tr>
<th align="left">Order #</th>
<th align="left">Product ID</th>
<th align="left">Product Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>#244</td>
<td>98</td>
<td>Product Name</td>
</tr>
</tbody>
</table>
When what I want to get is:
<table width="100%">
<thead>
<tr>
<th align="left">Order #</th>
<th align="left">Product ID</th>
<th align="left">Product Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>#265 YES</td>
<td>98</td>
<td>Product Name</td>
</tr>
<tr>
<td>#265 YES</td>
<td>99</td>
<td>Product Name</td>
</tr>
</tbody>
</table>
<table width="100%">
<thead>
<tr>
<th align="left">Order #</th>
<th align="left">Product ID</th>
<th align="left">Product Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>#244</td>
<td>98</td>
<td>Product Name</td>
</tr>
</tbody>
</table>
To get the duplicated ids you could use:
SELECT id,txn_id , COUNT(*)
FROM table_name
HAVING COUNT(*) > 1
Replace of course table_name with the name of your table
I ended up doing it this way:
$myArray = $wpdb->get_results("SELECT * FROM " . $license_table);
$newArray=array();
foreach($myArray as $val){
$newKey=$val->txn_id;
$newArray[$newKey][]=$val;
}
print_r($newArray);
foreach ($newArray as $key => $array){
?>
<table border="0" cellpadding="0" cellspacing="0">
<tr class="header">
<td width="73%" valign="top">KEY</td>
<td width="73%" valign="top">Product Id</td>
<td width="27%" valign="top">Product Name</td>
</tr>
<?php
foreach($array as $values) {
?>
<tr class="details">
<td width="27%" valign="top"><?php echo $key; ?></td>
<td width="73%" valign="top"><?php echo $values->product_id; ?></td>
<td width="27%" valign="top"><?php echo $values->product_name ?></td>
</tr>
<?php } ?>
</table>
<?php
}

Resources