React table optimization problem(HTML,CSS) - html

I am making a simple web page using React and I need a table on this page. The contents of the table are OK, but the table is not properly aligned. I do not see any problem in the code. How Can I Solve This?
import React from 'react'
const StuffList = () => {
return (
<div className='list-group'>
<table className="table table-hover table-danger"></table>
<thead>
<tr className="bg-primary">
<th scope="col">T.C</th>
<th scope="col">Name</th>
<th scope="col">Surname</th>
<th scope="col">City</th>
<th scope="col">Jobe</th>
<th scope="col">Salary</th>
<th scope="col">Hobbies</th>
<th scope="col">U.Graduate</th>
<th scope="col">Graduate</th>
<th scope="col">P.Graduate</th>
<th scope="col">Blood Group</th>
<th scope="col">Edit</th>
<th scope="col">Delete</th>
<th scope="col">Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>2826572</td>
<td>Mike</td>
<td>White</td>
<td>Kansas</td>
<td>Student</td>
<td>41</td>
<td>Parachute</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>ARH-</td>
<td><button className='btn btn-warning'>Update</button></td>
<td><button className='btn btn-danger'>Delete</button></td>
<td><button className='btn btn-info'>Details</button></td>
</tr>
</tbody>
</div>
)
}
export default StuffList

you can give the <tr style={{width:"100%",padding:"8px"}}> and for tds you can add
<td style={{padding:"8px}}>
if it didn't worked give the table and its parent div 100% width

Related

Jquery copy first column of table to each next column

I need for mobile view som manipulation of table. My table for desktop look like:
<table>
<thead>
<tr>
<th scope="row"> </th>
<th scope="col"> </th>
<th scope="col"><strong>Special Header</strong></th>
<th scope="col"> </th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><strong>First</strong></th>
<td><strong>Second</strong></td>
<td><strong>Third</strong></td>
<td><strong>fourth</strong></td>
</tr>
<tr>
<th scope="row"><strong>Text</strong></th>
<td>Text</td>
<td>Text</td>
<td>Text</td>
</tr>
</tbody>
</table>
For mobile devices I need to copy first colum to all other columns. Table should look like:
<table>
<thead>
<tr>
<th scope="row"> </th>
<th scope="col"> </th>
<th scope="row"> </th>
<th scope="col"><strong>Special Header</strong></th>
<th scope="row"> </th>
<th scope="col"> </th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><strong>First</strong></th>
<td><strong>Second</strong></td>
<th scope="row"><strong>First</strong></th>
<td><strong>Third</strong></td>
<th scope="row"><strong>First</strong></th>
<td><strong>fourth</strong></td>
</tr>
<tr>
<th scope="row"><strong>Text</strong></th>
<td>Text</td>
<th scope="row"><strong>Text</strong></th>
<td>Text</td>
<th scope="row"><strong>Text</strong></th>
<td>Text</td>
</tr>
</tbody>
</table>
I found some Jquery, but this code only append first column at the end:
$('#addcolumn').click(function() {
$('table tr').each(function() {
$(this).append($(this).find('th:first').clone());
});
});
Can you please help to make Jquery code working for my problem, thank!
Martin
You can use insertAfter this will insert element in the set of matched elements after the target .So, for tbody > td you can loop through tr and get first th cloned it then you can check if td is not last-child of tr if yes just add the cloned element after that td.Now , for thead you can simply use eq(0) to get first th and then use insertAfter to add the cloned after every th where scope="col".
Demo Code :
$('#addcolumn').click(function() {
///loop through tds
$('tbody td').each(function() {
//get th
var clone = $(this).closest("tr").find('th:first').clone()
//if td is not last
if (!$(this).is(':last-child')) {
$(clone).insertAfter(this); //insert the cloned th
}
});
//get the header first th
var headers = $("table").find("thead th:eq(0)").clone();
//insert cloned to th where scope=col and not last child
$(headers).insertAfter("thead th[scope=col]:not(:last-child)");
});
$('#normal').click(function() {
//remove th not first child from thead and tbody
$("thead th[scope=row]:not(:first-child)").remove();
$("tbody th[scope=row]:not(:first-child)").remove();
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<thead>
<tr>
<th scope="row"> </th>
<th scope="col"> </th>
<th scope="col"><strong>Special Header</strong></th>
<th scope="col"> </th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row"><strong>First</strong></th>
<td><strong>Second</strong></td>
<td><strong>Third</strong></td>
<td><strong>fourth</strong></td>
</tr>
<tr>
<th scope="row"><strong>Text</strong></th>
<td>Text</td>
<td>Text</td>
<td>Text</td>
</tr>
</tbody>
</table>
<button id="addcolumn">Add</button>
<button id="normal">Reset</button>

Responsive table in bootstrap

My question is quite simple, how do I make this table responsive using twitter bootstrap 4? Below is a JS Fiddle Link.
<div class="some-table-section">
<div class="container">
<table class="table some-table">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Plan 1</th>
<th scope="col">Plan 2</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Option 1</th>
<td>$1</td>
<td>$2</td>
</tr>
<tr>
<th scope="row">Option 2</th>
<td>1</td>
<td>2</td>
</tr>
<tr>
<th scope="row">Option 3</th>
<td>Unlimited</td>
<td>Unlimited</td>
</tr>
<tr>
<th scope="row"></th>
<td><a href="#" class="btn btn-primary">Select this plan</td>
<td><a href="#" class="btn btn-primary">Select this plan</td>
</tr>
</tbody>
</table>
</div>
</div>
What I would like to have is a responsive version of this table such that plan 2 is below plan 1 in the responsive version. PS. You can find the current CSS in the JS Fiddle Link.
You should check Bootstrap Docs: https://getbootstrap.com/docs/4.3/content/tables/#responsive-tables
Simply wrap your table with .table-responsive
Basic example:
<div class="table-responsive">
<table class="table">
...
</table>
</div>
You can have breakpoint specific responsive table using class table-responsive{-sm|-md|-lg|-xl}

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>).

Center <th> in bootstrap in double header table

Hello i have a table and i want to center a th between two other th.
I want to change the position of th Vieillesse de base to be displayed in the center of Provisionnel and Régularisation.
Here my HTML :
<div class="row mt-1">
<div class="col-12">
<table class="table table-striped table-adjust ">
<thead class="cordonnes-cabinet">
<tr>
<th scope="col">Date</th>
<th scope="col" style="text-align:center" colspan="2">Vieillesse de base</th>
<th scope="col" style="text-align:right">Complémentaire</th>
<th scope="col" style="text-align:right">Total</th>
</tr>
<tr>
<th scope="col">...</th>
<th scope="col" style="text-align:right">Provisionnel</th>
<th scope="col" style="text-align:right">Régularisation</th>
<th scope="col" style="text-align:right">...</th>
<th scope="col" style="text-align:right">...</th>
</tr>
</thead>
<tbody class="cordonnes-cabinet">
#for (int i = 0; i < echeancierGeneriqueAjustee.Count; i++)
{
<tr>
<th style="font-weight:100">#(echeancierGeneriqueAjustee[i]["Date"])</th>
<td style="text-align:right">#(echeancierGeneriqueAjustee[i]["MontantProv"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[i]["MontantRegul"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[i]["MontantComplement"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[i]["TotalEcheance"])</td>
</tr>
}
<tr>
<th style="font-size:14px">Total</th>
<td style="text-align:right">#(echeancierGeneriqueAjustee[0]["TotalProv"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[0]["TotalRegul"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[0]["TotalComplement"])</td>
<td style="text-align:right">#(echeancierGeneriqueAjustee[0]["Total"])</td>
</tr>
</tbody>
</table>
</div>
</div>
The key to do this is use html colspan in the th, to simulate equality of width with the second row. Then you only need to use .text-center.
In you particular case, use colspan="2" in the second th
JS FIDDLE DEMO
<table class="table">
<thead class="cordonnes-cabinet">
<tr>
<th>Date</th>
<th colspan="2" class="text-center">Vieillesse de base</th>
<th>Complémentaire</th>
<th>Total</th>
</tr>
<tr>
<th style="width:10%">...</th>
<th class="text-center">Provisionnel</th>
<th class="text-center">Régularisation</th>
<th>...</th>
<th>...</th>
</tr>
</thead>
<tbbody>
<tr>
<th>col1</th>
<td class="text-center">col2</td>
<td class="text-center">col3</td>
<td>col4</td>
<td>col5</td>
</tr>
</tbbody>
</table>
So the issue here is that your text is centered but the Column to the right is X wide and creates a optical illusion that your column is a lot wider.
I would set the column saying "Complémentaire" to text-align: left with class text-left then it will create the illuion you want.
Ive attached a picture where you can see that your code actually centers the text its just an optical illuion
This is how it would look with left aligned in the blue column:
And now its just a question on how to make it pretier with paddings on the td's and th's

How to implement sort Table according to a single column in Angular 6 (using boostrap)

Can anyone please suggest the best way to implement sorting in angular 6 using botstrap. This is my table.
I need to sort the table using mrp , ssp ,ymp .
I tried to search for tutorials , but there is angularjs implementation all over the internet .
Can anyone suggest a proper angular 6 implemetation using data table
<table id="myTable" class="table table-striped table-bordered table-dark" #myTable>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Id</th>
<th scope="col">Image</th>
<th scope="col">Name</th>
<th scope="col">Seller</th>
<th scope="col">Category</th>
<th scope="col">Status</th>
<th scope="col" sortable="mrp.value" class="sortable">MRP
</th>
<th scope="col" class="sortable">SSP
</th>
<th scope="col" class="sortable" >YMP
</th>
<th scope="col" class="sortable">Date Added
</th>
</tr>
</thead>
<tbody *ngFor ="let tempProduct of products">
<tr>
<th scope="row"><input type="checkbox" name="cbProducts"
value=`${{tempProduct.id}}`></th>
<td>{{tempProduct.id}}</td>
<td>
<img
src="http://localhost:8080/YourMart-PMP-Admin-
Panel/resources/images/{{tempProduct.primaryImg}}"
height="50" width="50">
</td>
<td>{{tempProduct.name}}</td>
<td>{{tempProduct.seller.name}}</td>
<td>{{tempProduct.category.name}}</td>
<td>{{tempProduct.status}}</td>
<td >{{tempProduct.mrp}}</td>
<td >{{tempProduct.ssp}}</td>
<td >{{tempProduct.ymp}}</td>
<td >{{tempProduct.created}}</td>
</tr>
</tbody>
</table>