bootstrap table is not responsive - css

I have a table which fills data from database. Though i had use the bootstrap when i kept on decreasing the width of the browser, from one point onward the table is going outside the container. How can i make this responsive ? Following are the attached images
<table class="table table-responsive table-bordered">
<tr>
<th>Spare Id</th>
<th>Part Number</th>
<th>Quantity</th>
<th>Price</th>
<th>Warranty</th>
{{--<th>Description</th>--}}
<th>Spare Image</th>
<th>
<input type="text" class="form-control" id="search" placeholder="Search Spare">
</th>
</tr>
<tbody id="tableModel">
<?php
foreach($spares as $spare){
?>
<tr>
<td ><?php echo $spare->id;?></td>
<td ><?php echo $spare->partNumber;?></td>
<td ><?php echo $spare->quantity;?></td>
<td ><?php echo 'Rs.'. $spare->price;?></td>
<td ><?php echo $spare->warranty;?></td>
<td><?php echo '<img class="img-responsive" src="data:image/jpeg;base64,'.base64_encode( $spare->image ).'"/>';?></td>
<td>
<a class=" btn btn-success btn-sm" data-toggle="modal" data-target="#modalEdit" onclick="EditBrand('<?php echo $brand->brandName;?>','<?php echo $brand->id;?>')" >Edit </a>
<a onclick="DeleteBrand(<?php echo $brand->id;?>)" style="" class=" btn btn-danger btn-sm" >Delete </a>
</td>
</tr>
<?php }?>
</tbody>
</table>

If you use bootstrap. Wrap your table in a div with table-responsive class.
<div class="table-responsive">
<table class="table">
...
</table>
</div>
That should work if bootstrap is correctly integrated. Please show your code. Many more people would help you.
You can find this specific information here:
https://getbootstrap.com/docs/5.0/content/tables/#responsive-tables

I have worked a lot n this issue and found a good solution for this bootstrap table responsiveness issue. Just use the CSS below:
.table{
display: block !important;
overflow-x: auto !important;
width: 100% !important;
}

Add this line, that will solve your problem.
<div class='table-responsive'>
<div style="overflow-x:auto;">

Make sure you checked you have inserted enough data in table. Sometimes there is just not enough data to trigger 'table-responsive' property.

Related

Responsive drop-down menu with table inside

Hi I'm trying to obtain responsive menu on navbar in application on which I work with bootstrap 3. My menu has element with bell icon. The purpose of this one is to remind user some information. Below I show that menu element on screen:
I have fixed settings for width of my menu. I'd like to have responsive menu, not static, because this application should work on few screen resolutions. What should I obtain that? I tried to obtain that by pecrentage property for: width, min-with properties, but it has crashed.
Below I show html tags and CSS settings:
Html:
<li class="dropdown ng-isolate-scope open" loader="remainderLoading"><a ng-show="!loader" id="reminderLink" class="dropdown-toggle" data-toggle="dropdown" style="font-size:18px; cursor:pointer;" ng-click="removeNotification()" aria-expanded="true"><i class="fa fa-bell"></i></a>
<!-- ngIf: numOfRemindedNotes && !loader && !clicked -->
<div id="reminderMenu" class="dropdown-menu">
<div class="form-group col-md-7 disabled">
<label>Reminder's date:</label>
<input type="text" class="form-control ng-pristine ng-untouched ng-valid ng-isolate-scope ng-not-empty ng-valid-date ng-valid-required" ng-change="getNotesByDate()" initdate="new Date()" ng-click="noteDatepicker.opened = true" uib-datepicker-popup="" ng-model="dateNotes.value" is-open="noteDatepicker.opened" ng-required="true" close-text="Close" readonly="" required="required"><div uib-datepicker-popup-wrap="" ng-model="date" ng-change="dateSelection(date)" template-url="uib/template/datepickerPopup/popup.html" class="ng-pristine ng-untouched ng-valid ng-scope ng-not-empty"><!-- ngIf: isOpen -->
</div>
</div>
<div ng-show="noteLoading" class="ng-hide">
<img width="32" height="32" src="/packages/img/loader.gif">
</div>
<div class="col-md-12">
<table id="reminderTable" class="table table-bordered table-striped" ng-show="!noteLoading">
<tbody>
<tr id="reminderTableElement">
<td class="col-md-3">
Case Id
</td>
<td class="col-md-3">
Trans id
</td>
<td class="col-md-3">
Type customer
</td>
<th class="col-md-3">
Note
</th>
<td class="col-md-3">
Date
</td>
<td class="col-md-3"></td>
</tr>
<!-- ngRepeat: note in notes.notesForBasicCustomer --><tr ng-repeat="note in notes.notesForBasicCustomer" id="reminderTableElement" class="ng-scope">
<td style="cursor: pointer;">
<a target="_self" ng-click="editCaseById(note.case_id)" class="ng-binding">426024</a>
</td>
<td class="ng-binding">
639252-2
</td>
<td>Basic</td>
<td class="ng-binding">
asdsadsa
</td>
<td class="ng-binding">
2018-08-09
</td>
<td>
<div class="btn btn-primary" ng-disabled="noteLoading" ng-click="hideReminder(note['0'].id,'basic')">Close
</div>
</td>
</tr><!-- end ngRepeat: note in notes.notesForBasicCustomer --><tr ng-repeat="note in notes.notesForBasicCustomer" id="reminderTableElement" class="ng-scope">
<td style="cursor: pointer;">
<a target="_self" ng-click="editCaseById(note.case_id)" class="ng-binding">426011</a>
</td>
<td class="ng-binding">
639252-2
</td>
<td>Basic</td>
<td class="ng-binding">
asdsa
</td>
<td class="ng-binding">
2018-08-09
</td>
<td>
<div class="btn btn-primary" ng-disabled="noteLoading" ng-click="hideReminder(note['0'].id,'basic')">Close
</div>
</td>
</tr><!-- end ngRepeat: note in notes.notesForBasicCustomer -->
<!-- ngRepeat: note in notes.notesForAdditionalCustomers -->
</tbody>
</table>
</div>
</div>
</li>
CSS:
#reminderTableElement{
font-size: 12px;
}
#reminderMenu{
min-width: 540px;
}
I would be grateful for help. Best regards ;)
You should use #media tags to implement styles. For example
#media (min-width: 1600px) {
#reminder-menu {
...
}
}
It is considered best practice to design for mobile first, so you would use min-width: 540px or whatever your smallest breakpoint is first, then add more breakpoints as needed.

fixed header and footer in dompdf

I have a table of data which dynamically producing, and I converted the html page into pdf using dom pdf.I want to add header and footer on each page. but the problem is when the data is large the footer is not stable, and also the the header and footer is not repeating on each page.
<div class="conainer-fluid">
<div class="row0">
<div class="header"><img src="<?php echo base_url()?>public/images/alhamed.jpg" style="width: 700px;"></div>
</div>
<div class="card-body">
<div class="table-responsive-sm">
<table class="table table-striped">
<thead class="thead-default">
<tr>
<th class="text-center"> # </th>
<th> Product </th>
</tr>
</thead>
<tbody>
<?php
for($j=0;$j<40;$j++)
{
?>
<tr>
<td>haii</td>
</tr>
<?php
if($i<$count)
{
$i++;
}
}
?>
</tbody>
</table>
</div>
<div class="conainer-fluid">
<div class="row1">
<div class="footer"><img src="<?php echo base_url()?>public/images/footer.jpg" style="width: 700px; margin-bottom: 150px;"></div>
css
table td{page-break-after: always;}
.header { position: fixed; }
.row1{position: fixed;background-color: lightblue;}
how can i make the header and footer repeating on each page of pdf according to the data ?

Bootstrap rows and columns not working properly inside for each loop

I tried to use bootstrap row and columns classes inside a for each loop and some extra spaces are displayed as unexpected.
First I used the following code and it worked well.
<table border="0" id="myTable" class="table" >
<thead border-bottom="0">
<tr>
<th border-bottom="0" style="display: none;">Gem</th>
<th border-bottom="0" style="display: none;">Name</th>
</tr>
</thead>
<tbody>
#foreach(App\GemStone::where('active',TRUE)->orderBy('created_at', 'desc')->get() as $gemStone)
<div class="row">
<tr>
<td style="display: none;" >{{$gemStone->created_at}}</td>
<td>
<div class="col-sm-3">
<div align="center">
<img alt="Gem Stone Pic" src="{{route('get_image',['id' => $gemStone->id])}} " class="img-circle img-responsive">
</div>
</div>
<div class="col-sm-3">
<h3><b>{{$gemStone->type->type}}</b></h3>
#if($gemStone->shop->user->id == Auth::user()->id)
[Edit]<br>
#endif
{{$gemStone->size->size}}<br>
LKR: {{$gemStone->price}}<br>
<div>
{{$gemStone->description}}<br>
{{$gemStone->created_at}}
</div>
</div>
<div class="col-sm-3"> free space of 3 cols </div>
<div class="col-sm-3">free space of 3 cols </div>
</td>
</tr>
</div>
#endforeach
</tbody>
</table>
above code gave a view like this image. In order to use the free space marked in the picture, I tried adding another column by creating another <td> ... </td> inside <tr> </tr> using $counter variable as below.
<table border="0" id="myTable" class="table" >
<thead border-bottom="0">
<tr>
<th border-bottom="0" style="display: none;">Gem</th>
<th border-bottom="0" style="display: none;">Name</th>
<th border-bottom="0" style="display: none;">Name</th>
</tr>
</thead>
<tbody>
<?php $count = 0 ?>
#foreach(App\GemStone::where('active',TRUE)->orderBy('created_at', 'desc')->get() as $gemStone)
<?php $count = $count + 1 ?>
#if($count % 2)
<tr>
<div class="row">
<td style="display: none;" >{{$gemStone->created_at}}</td>
#endif
<td>
<div class="col-sm-3">
<div align="center">
<img alt="Gem Stone Pic" src="{{route('get_image',['id' => $gemStone->id])}} " class="img-circle img-responsive">
</div>
</div>
<div class="col-sm-3">
<h3><b>{{$gemStone->type->type}}</b></h3>
#if($gemStone->shop->user->id == Auth::user()->id)
[Edit]<br>
#endif
{{$gemStone->size->size}}<br>
LKR: {{$gemStone->price}}<br>
<div>
{{$gemStone->description}}<br>
{{$gemStone->created_at}}
</div>
</div>
</div>
</td>
#if(!($count % 2))
</div>
</tr>
#endif
#endforeach
#if($count%2)
<td>extra cell when odd</td>
</div>
</tr>
#endif
Result looked like this which is unexpected. I tried changing the place of <div class='row'> and <div class = 'col-s6'>in several ways, but nothing worked. And I couldn't really find a mistake in the code as well . It would be grateful if someone can point where I go wrong while using the columns and row classes.
And I'm using jquery datatables to get the table view.
Add the bootstrap classes to your table elements, instead of adding additional div elements.
<table>
<tr class="row">
<td class="col-md-4">1</td>
<td class="col-md-4">2</td>
<td class="col-md-4">3</td>
</tr>
</table>

bootstrap searchbox and pagination are in the middle. I want them at the right

<?php
// include Database connection file
include("connectionfile.php");
// Design initial table header
$data = '<table class="table table-bordered table-striped table-hover" id="supplierTable" style="max-width: 1000px">
<thead>
<tr>
<th>No</th>
<th>Sym</th>
<th>Name</th>
<th>Tax</th>
<th>Address</th>
<th>Phone</th>
<th>Email</th>
<th>Products</th>
<th>Update</th>
<th>Delete</th>
</tr>
</thead>';
$query = "SELECT * FROM suppliers";
$result=mysqli_query($con,$query);
// $row=mysqli_fetch_array($result);
if (!$result) {
exit(mysqli_error());
}
// if query results contains rows then featch those rows
if(mysqli_num_rows($result) > 0)
{
$number = 1;
while($row = mysqli_fetch_array($result))
{
$data .= '<tr>
<td align="right"> '.$number.'</td>
<td align="center">'.$row['symbol'].'</td>
<td align="center">'.$row['companyname'].'</td>
<td align="center">'.$row['taxnumber'].'</td>
<td align="center">'.$row['address'].'</td>
<td align="center"> +'.$row['phone'].'</td>
<td align="center">'.$row['email'].'</td>
<td>
<button onclick="GetSupplierProducts('.$row['id'].')" class="btn btn-success text-center">All Products</button>
</td>
<td>
<button onclick="GetSupplierDetails('.$row['id'].')" class="btn btn-warning text-center">Update</button>
</td>
<td>
<button onclick="DeleteSupplier('.$row['id'].')" class="btn btn-danger text-center">Delete</button>
</td>
</tr>';
$number++;
}
}
else
{
// records now found
$data .= '<tr><td colspan="6">Records not found!</td></tr>';
}
$data .= '</table>';
echo $data;
?>
<script>
$(document).ready(function() {
$('#supplierTable').DataTable({
bJQueryUI: true,
sPaginationType: "full_numbers"
});
});
</script>
<script src="../bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="../bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
<script src="../dist/js/sb-admin-2.js"></script>
This is my code it displays the search bar and pagination at the middle. I would like them to be at the right. any ideas? Here is a picture:
I would simply love to see my search box under add a new supplier.
thanks
Adding the three scripts at the end shows the search box, entries and pagination. well, I have the button in a main page:
<div class="pull-right">
<button class="btn btn-success" data-toggle="modal" data-target="#add_new_supplier_modal">Add A New Supplier</button>
</div>
I can't import your bower components but i can give you some idea of how things should be arranged.
The basic idea is that you need to place all of your 3 components and also the table in their appropriate boxes. And this boxes are separated in groups. Start simple in a separate file - fake static data.. After you have the bare bones css+html working, then you simply place it inside php and do rendering with real dynamic data..
This is the code:
<div class="parent_div" style="margin-top: 20px;"> ///everything goes in here including the table
<!--only the 3 components in here-->
<div class="the_3_components_you_have">
<!-- the button is first component, "text-right" is a bootstrap class you need to align stuff to right. Doesn't work on the button directly so we wrap it in a div -->
<div class="text-right" style="margin-right:50px;">
<button class="btn btn-success" >Add a New Suplier</button>
</div>
<!-- Display on the same row the pagination and search component. But again text-right only works on display:block so we need position relative on the pagination element-->
<div>
<div style="position: relative; top: 23px; left: 20px; ">Show pagination Component.</div>
<div class="text-right" style="margin-right: 50px; ">Search stuff: <input style="margin: 0px;" type="text"></div>
</div>
</div>
<!-- the table separately goes in here -->
<div>
Table goes here.
</div>
</div>
Instead my styles - you can create your own classes, tweak them as you like, and instead of text, you can place the script tags you have, and they will load appropriately in that box. Chrome Developer Tools will help you. Here is a preview:
Learn about Bootstrap clases and Bootstrap positioning here.
and you can find this code as a live example here: JsBin Link

overriding primefaces 3.1 css for datatable

I am trying to override the css classes from primefaces 3.1, I was looking for a pattern for the class name to override.
I tried:
.ui-datatable table {}
.ui-datatable .ui-datatable-header,.ui-datatable .ui-datatable-footer {}
.ui-datatable .ui-datatable-header {}
.ui-datatable th,.ui-datatable tfoot td {}
.ui-datatable .ui-datatable-data td,.ui-datatable .ui-datatable-data-empty td{}
But only the rows content got centralized but was not able to change header bgcolor and other stuff.
Then I realized that may be the classes I overwrote might not have been used.
Surprisingly, I found the generated source code are not using these as class...
<div id="form:j_id1915418705_722af8cd" class="ui-datatable ui-widget">
<table role="grid"><thead><tr role="row">
<th id="form:j_id1915418705_722af8cd:j_id1915418705_722af894" class="ui-state-default" role="columnheader">
<div class="ui-dt-c">
<span><span class="outputText">Model</span></span>
</div>
</th>
<th id="form:j_id1915418705_722af8cd:j_id1915418705_722af942" class="ui-state-default" role="columnheader">
<div class="ui-dt-c">
<span><span class="outputText">Color</span></span>
</div>
</th></tr></thead><tfoot></tfoot>
<tbody id="form:j_id1915418705_722af8cd_data" class="ui-datatable-data ui-widget-content">
<tr data-ri="0" data-rk="BMW" class="ui-widget-content ui-datatable-even" role="row" aria-selected="false">
<td role="gridcell">
<div class="ui-dt-c">
<span class="outputText">BMW</span>
</div>
</td>
<td role="gridcell">
<div class="ui-dt-c">
<span class="outputText">Black</span>
</div>
</td>
</tr>
<tr data-ri="1" data-rk="Audi" class="ui-widget-content ui-datatable-odd" role="row" aria-selected="false">
<td role="gridcell">
<div class="ui-dt-c">
<span class="outputText">Audi</span>
</div>
</td>
<td role="gridcell">
<div class="ui-dt-c">
<span class="outputText">White</span>
</div>
</td>
</tr>
</tbody>
</table><input type="hidden" id="form:j_id1915418705_722af8cd_selection" name="form:j_id1915418705_722af8cd_selection" value="" autocomplete="off" />
Can somebody tell me how to I be able to change table headers, borders, alternate rows color...
Can somebody provide me a pattern for How to know what class in PF to override looking at the generted source code.
Thanks in advance.
First of the classes are included here in the markup:
<div id="form:j_id1915418705_722af8cd" class="ui-datatable ui-widget">
The other child classes automatically apply themselves to the other elements.
Your custom CSS may actually be overridden by the Primefaces CSS styles if you are including these styles in a seperate CSS file linked from head.
To make sure that your custom CSS applies itself to the page try adding the custom CSS inline to the page body and see if it applies then.

Resources