Bootstrap - Customise Table Row Highlight Class for One Page - html

I have a Bootstrap table that allows users to select rows which adds the class="success" to the select Row. I'm using the defaults for the contextual classes:
https://getbootstrap.com/docs/3.3/css/#tables-contextual-classes
but the customer would like, just for this particular page, to have the success be a more brighter green that stands out more.
Here's an example of the table:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<table class="table table-condensed table-striped table-bordered">
<thead>
<th scope="col">Serial #</th>
<th scope="col">Product Code</th>
<th scope="col">ID</th>
<th scope="col">Description</th>
<th class="text-center" scope="col">Select</th>
</thead>
<tbody>
<tr class="success" id="PZs456">
<td>ZK2342MFM</td>
<td>JMPG</td>
<td>98651217</td>
<td>Keyboard - Bluetooth</td>
<td class="text-center">
<button type="button" class="btn btn-success btn-sm">Select</button>
</td>
</tr>
</tbody>
</table>
What's the best way to change the 'success' colour so it's a brighter green just for this page without changing the Bootstrap CSS itself?

.new-green {
background: #00ff00 !important;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<table class="table table-condensed table-striped table-bordered">
<thead>
<th scope="col">Serial #</th>
<th scope="col">Product Code</th>
<th scope="col">ID</th>
<th scope="col">Description</th>
<th class="text-center" scope="col">Select</th>
</thead>
<tbody>
<tr class="success" id="PZs456">
<td>ZK2342MFM</td>
<td>JMPG</td>
<td>98651217</td>
<td>Keyboard - Bluetooth</td>
<td class="text-center"><button type="button" class="btn btn-success btn-sm new-green">Select</button></td>
</tr>
</tbody>
</table>
I do not know if this is a best way but since there are a lot of !important things in bootstrap why dont you use your own as new class?

Related

Change cell text in table depending on boolean value - Html

I have a table that displays the properties from an object. I would want to know if there is an easy way of changing the text the cell display instead of the true/false that the value is set to.
Example. I have a column that informs if the object is open(true) or closed(false).
Instead of showing true/false I would like to show open/closed.
The column is "State". It is a boolean attribute.
Is it possible to make this only on the html or should I change something in the component file? (It's angular)
<table class="table table-dark table-condensed table-bordered table-striped table-hover">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">State</th>
<th scope="col">Resolved By</th>
<th scope="col">Hours to resolve</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let bug of bugs">
<th scope = "row">{{bug.id}}
<td>{{bug.name}}</td>
<td>{{bug.description}}</td>
<td>{{bug.state}}</td>
<td>{{bug.resolvedBy}}</td>
<td>{{bug.hoursToResolve}}</td>
</tr>
</tbody>
</table>
</div>
Thanks!
Great example for a ternary operator:
<table class="table table-dark table-condensed table-bordered table-striped table-hover">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">State</th>
<th scope="col">Resolved By</th>
<th scope="col">Hours to resolve</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let bug of bugs">
<th scope = "row">{{bug.id}}
<td>{{bug.name}}</td>
<td>{{bug.description}}</td>
<td>{{bug.state ? 'True Value Here' : 'False Value Here'}}</td>
<td>{{bug.resolvedBy}}</td>
<td>{{bug.hoursToResolve}}</td>
</tr>
</tbody>
</table>
</div>

How Do You Make Bootstrap Responsive Tables Wider

I'm using bootstrap 5 to create responsive tables which works fine but when one column has a lot of text all other columns get squished making it look weird. I would like to set it so that the columns with smaller amounts of texts and the table headers to not get cut off. I also have the table set to responsive which in bootstrap's css sets overflow-x: auto.
Picture of what the table looks like on mobile
Second Picture of mobile
Picture of what it looks like on pc
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
</head>
<div class="container">
<div class="table-responsive">
<table class="table table-sm table-bordered table-hover">
<thead class="table-warning">
<tr>
<th scope="col">Ticket ID</th>
<th scope="col">Asset Type Or User</th>
<th scope="col">Asset Tag</th>
<th scope="col">User ID</th>
<th scope="col">Name</th>
<th scope="col">Location</th>
<th scope="col">Description</th>
<th scope="col">Date Added</th>
<th scope="col">Priority</th>
<th scope="col">Mark As Done</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">4</th>
<td>computer</td>
<td>C-Place-Holder</td>
<td>NA</td>
<td>Tom Blow</td>
<td>In Health Building, Bottom Floor</td>
<td>User would like to print color, has missing files, and monitor is flickering.</td>
<td>2021-02-24</td>
<td>3</td>
<td>
<button class="btn btn-primary" id="4" onclick="markDone(4)">Done</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
To make it 100% you have to add this command to your CSS
.table-responsive { display: table; } but this won't work for smaller screens. You have to use media queries for that.
Hope my answer helps you.

Trying to apply CSS text decoration after input checkbox is checked

I am having issue trying to apply a CSS style to a sibling element after an input of checkbox has been checked. My goal is to apply the text-decoration of line-through and text-decoraction-color red to the sibling element.
DEMO: enter link description here
input:checked + td.p1Amount {
text-decoration: line-through;
text-decoration-color: red;
}
<table class="table table-striped table-bordered table-hover table-sm table-responsive">
<thead>
<tr>
<th scope="col">Item</th>
<th scope="col">Due Date</th>
<th scope="col">Paid</th>
<th scope="col">Amount</th>
<th scope="col">Notes</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Utility</th>
<td>05/15/2020</td>
<td><input type="checkbox"></td>
<td class="p1Amount">$1.00</td>
<td>Confirmation #5477ff59de</td>
</tr>
</tbody>
</table>
Am I not using the right CSS selector to select the sibling after the checkbox has been checked?
you can do it by vanilla js
document.querySelector(".checkbox").onchange = function(){
var check = document.querySelector("input").checked;
if(check == true){
document.querySelector(".p1Amount").style.textDecoration = "line-through";
document.querySelector(".p1Amount").style.textDecorationColor = "red";
}else {
document.querySelector(".p1Amount").style.textDecoration = null;
document.querySelector(".p1Amount").style.textDecorationColor = null;
}
} ;
<table class="table table-striped table-bordered table-hover table-sm table-responsive">
<thead>
<tr>
<th scope="col">Item</th>
<th scope="col">Due Date</th>
<th scope="col">Paid</th>
<th scope="col">Amount</th>
<th scope="col">Notes</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Utility</th>
<td>05/15/2020</td>
<td><input class="checkbox" type="checkbox"></td>
<td class="p1Amount">$1.00</td>
<td>Confirmation #5477ff59de</td>
</tr>
</tbody>
</table>
I used JQuery. Please Try this...
(function ($) {
$(document).ready(function(){
$(".check").click(function(){
if($(".check").prop('checked')){
$(".p1Amount").css("text-decoration","line-through");
$(".p1Amount").css("text-decoration-color","red");
}else{
$(".p1Amount").css("text-decoration","");
$(".p1Amount").css("text-decoration-color","");
}
});
});
}(jQuery));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table class="table table-striped table-bordered table-hover table-sm table-responsive">
<thead>
<tr>
<th scope="col">Item</th>
<th scope="col">Due Date</th>
<th scope="col">Paid</th>
<th scope="col">Amount</th>
<th scope="col">Notes</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Utility</th>
<td>05/15/2020</td>
<td><input type="checkbox" class="check"></td>
<td class="p1Amount">$1.00</td>
<td>Confirmation #5477ff59de</td>
</tr>
</tbody>
</table>

Can't align the table head and the table body in html, using angular with in-memory-data

I can't seem to align the table head with the table body.
This is for my project making a web-type student data-storing database.
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Id</th>
<th scope="col">NIM</th>
<th scope="col">Nama</th>
<th scope="col">Jenis Kelamin</th>
<th scope="col">Alamat</th>
<th scope="col">Nama Bapak</th>
<th scope="col">Nama Ibu</th>
<th scope="col">Jurusan</th>
<th scope="col">Prodi</th>
<th scope="col">IPK Terakhir</th>
<th scope="col">Hapus</th>
</tr>
</thead>
<tbody *ngFor="let mhs of mhss">
<a routerLink="/detail/{{mhs.id}}">
<tr>
<td>{{mhs.id}}</td>
<td>{{mhs.nim}}</td>
<td>{{mhs.name}}</td>
<td>{{mhs.jk}}</td>
<td>{{mhs.alamat}}</td>
<td>{{mhs.nama_bapak}}</td>
<td>{{mhs.nama_ibu}}</td>
<td>{{mhs.jurusan}}</td>
<td>{{mhs.prodi}}</td>
<td>{{mhs.ipk}}</td>
<td><button class="delete" title="delete mhs"
(click)="delete(mhs)">HAPUS</button></td>
</tr>
</a>
</tbody>
</table>
My image:
Your code is generating a new <tbody> for every item in your array. Add the *ngfor structural directive to your table rows (<tr>).

Fix table cells in HTML/CSS

I am trying to adapt some parts of my web application for mobile devices, and I am currently working on the following form using Html/css.
I came across this little problem concerning the table. In fact, I can't fix the size of the table cells. For the moment I am using the following code:
<table class="table table-striped table-hover table-bordered" id="sample_editable_1">
<thead>
<tr>
</tr>
<tr>
<th style="width:10px" >Date d'ajout </th>
<th style="width:10px">NOM DU FICHIER</th>
<th style="width:10px">Ajouté par </th>
</tr>
</thead>
<tbody>
<th>19/22/2016 </th>
<th>25_02_2016_file_name </th>
<th>testla team Fsqsf qsfqsqsfqg qsdg sdgsdg sdsgd sdsd</th>
</tbody>
</table>
so what's the right way to do it? thanks in advance
try with this below code it may help you.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="table-responsive">
<table class="table table-striped table-hover table-bordered" id="sample_editable_1">
<thead>
<tr>
</tr>
<tr>
<th style="width:10px" >Date d'ajout </th>
<th style="width:10px">NOM DU FICHIER</th>
<th style="width:10px">Ajouté par </th>
</tr>
</thead>
<tbody>
<th>19/22/2016 </th>
<th>25_02_2016_file_name </th>
<th>testla team Fsqsf qsfqsqsfqg qsdg sdgsdg sdsgd sdsd</th>
</tbody>
</table>
</div>
use width="100%" and it will take up the full space of the parent div / span that it is in.
If you are developing for mobile I would recommend using Bootstrap if you know it / looking at it if you don't. It's a very handy library for HTML when developing mobile compatible webpages.
Instead you can use a scroll for the table
table{overflow-x:auto}