css issue table design - html

please can you help me to fix the design to make data more clear ,i will be very grateful if you help me ,thanks for your answer in advance
this is my css file
table-layout: fixed;
width: 100%;
border-collapse: collapse;
table-layout: fixed;
overflow: hidden;
}
this is my html file
<div class="col-md-12">
<div class="table-wrap">
<table class="table table-striped" >
<thead>
<tr>
<th class="odd" colspan="4">id</th>
<th class="odd" colspan="4">name</th>
<th *ngIf="isAdmin()" class="odd" colspan="4"> password</th>
<th class="odd" colspan="4">role</th>
<th class="odd" colspan="4"class="corner wideRow">email</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let el of users | paginate: { itemsPerPage: 2, currentPage: p }">
<th class="odd" colspan="4" ></th>
<td class="odd" colspan="4" >{{el.id}} </td>
<td class="odd" colspan="4" >{{el.username}}</td>
<td *ngIf="isAdmin()" class="odd" colspan="4">{{el.password}}</td>
<td class="odd" colspan="4" >{{el.role}}</td>
<td class="odd" colspan="4" >{{el.email}}</td>
<td class="odd" colspan="4">
<tr>
<a *ngIf="isAdmin()"
class="btn btn-danger" (click) = "deleteUser(el.id)" >Delete</a>
<a *ngIf="isAdmin()" class="btn btn-success" data-original-title="Edit">Edit</a>
</tr>
</td>
</tbody>
</table>
</div>
</div>
</div>
<pagination-controls (pageChange)="p = $event"></pagination-controls>
this the result ,it's not clear and i didn't khnow how to fixed it
when i add in csstable td { word-break: break-all;
}**
the result
result 2

1.) Having colspan="4" in each cell does not make any sense.
2.) The first (empty) th element in the tbody rows causes the misaligning you wrote about. Erase that to have IDs under the "id" header, names under the "name" header etc.
3.) You need an additional th cell in the header row (at the end) to have the same amount of cells as in the rows below it (above the cells with the nested tables which contain the two buttons).
.table-striped {
width: 100%;
border-collapse: collapse;
}
table td {
border: 1px solid #ddd;
word-break: break-all;
}
<table class="table table-striped">
<thead>
<tr>
<th class="odd">id</th>
<th class="odd">name</th>
<th *ngIf="isAdmin()" class="odd"> password</th>
<th class="odd">role</th>
<th class="odd">email</th>
<th class="odd"></th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let el of users | paginate: { itemsPerPage: 2, currentPage: p }">
<td class="odd">{{el.id}} </td>
<td class="odd">{{el.username}}</td>
<td *ngIf="isAdmin()" class="odd">{{el.password}}</td>
<td class="odd">{{el.role}}</td>
<td class="odd">{{el.email}}</td>
<td>
<table>
<tr>
<td>
<a *ngIf="isAdmin()" class="btn btn-danger" (click)="deleteUser(el.id)">Delete</a>
</td>
<td>
<a *ngIf="isAdmin()" class="btn btn-success" data-original-title="Edit">Edit</a>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>

Add this css
table td {
word-break: break-all;
}
And use this corrected html. Make sure you header columns and body columns are equals.
<div class="col-md-12">
<div class="table-wrap">
<table class="table table-striped">
<thead>
<tr>
<th class="odd" colspan="4">id</th>
<th class="odd" colspan="4">name</th>
<th *ngIf="isAdmin()" class="odd" colspan="4"> password</th>
<th class="odd" colspan="4">role</th>
<th class="odd" colspan="4">email</th>
<th class="odd" colspan="4"></th>
</tr>
</thead>
<tbody>
<tr *ngFor="let el of users | paginate: { itemsPerPage: 2, currentPage: p }">
<td class="odd" colspan="4">{{el.id}} </td>
<td class="odd" colspan="4">{{el.username}}</td>
<td *ngIf="isAdmin()" class="odd" colspan="4">{{el.password}}</td>
<td class="odd" colspan="4">{{el.role}}</td>
<td class="odd" colspan="4">{{el.email}}</td>
<td>
<table>
<tr>
<td>
<a *ngIf="isAdmin()" class="btn btn-danger" (click)="deleteUser(el.id)">Delete</a>
</td>
<td>
<a *ngIf="isAdmin()" class="btn btn-success" data-original-title="Edit">Edit</a>
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>

Related

How to change background color of TR on hover?

I am trying to highlight the entire row of my table when user hovers over it. But only the TD changes background color instead of the entire row.
CSS:
.addItem_tr :hover{
background: blue;
}
Html
<table>
<thead>
<tr>
<th width="15%" ></th>
<th width="35%" ></th>
<th width="50%" ></th>
</tr>
</thead>
<tbody>
<tr className="addItem_tr">
<td className="td_add_serviced_item" >{item.quantity}</td>
<td className="td_add_serviced_item" >{item.productID}</td>
<td className="td_add_serviced_item" >{item.productInfo.productDescription}</td>
</tr>
<tr className="addItem_tr">
<td className="td_add_serviced_item" >{item.quantity}</td>
<td className="td_add_serviced_item" >{item.productID}</td>
<td className="td_add_serviced_item" >{item.productInfo.productDescription}</td>
</tr>
</tbody>
</table>

How to have a full-width row into a table having image

I want to insert a full width row as shown in the below image by Arrow
I have tried colspan, rowspan but did not work for me so removed from question (otherwise question will mess up).
here is what i have tried: https://jsfiddle.net/eabangalore/y3Lt470z/16/
table td {
padding: 5px;
}
<table width="500px" border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th style="width:3%"></th>
<th style="width:10%">Name</th>
<th style="width:10%">Age</th>
<th style="width:10%">Designation</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div style="width:50px;height:70px;border-radius:50%;">
<img style="width:100%;height:100%;" src="https://via.placeholder.com/150"/>
</div>
</td>
<td align="center">Alpha</td>
<td align="center">21 year</td>
<td align="center">Software</td>
</tr>
<tr>
<td>
<div style="width:50px;height:70px;border-radius:50%;">
<img style="width:100%;height:100%;" src="https://via.placeholder.com/150"/>
</div>
</td>
<td align="center">Alpha</td>
<td align="center">21 year</td>
<td align="center">Software</td>
</tr>
</tbody>
</table>
Qusetion: i want to add a full-width row as shown by arrow in red color area (above image)
Note: i cannot change table into divs as i'm working on maintenance project.
You looking for this table structure. You have to use once rowspan and once colspan.
<table width="500px" border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th style="width:3%"></th>
<th style="width:10%">Name</th>
<th style="width:10%">Age</th>
<th style="width:10%">Designation</th>
</tr>
</thead>
<tr>
<th class="" rowspan="2">
<img style="width:100%;height:100%;" src="https://via.placeholder.com/150"/>
</th>
<th class="">1</th>
<th class="">2</th>
<th class="">3</th>
</tr>
<tr>
<td class="" colspan="4">new row</td>
</tr>
<tr>
<th class="" rowspan="2">
<img style="width:100%;height:100%;" src="https://via.placeholder.com/150"/>
</th>
<th class="">a</th>
<th class="">b</th>
<th class="">c</th>
</tr>
<tr>
<td class="" colspan="4">new row</td>
</tr>
</table>
Small Note: use instead inline style classes.

cdk virtual scrolling with sticky header html table angular

I am getting more than 30000 records from backend to list in frontend, So using cdk-virtual-scroll I can able to achieve this. I have created normal table enclosed with cdk-tag
<cdk-virtual-scroll-viewport [itemSize] = "20">
<div class="result_table">
<table class="dataframe" border="1">
<thead>
<tr>
<th >
Name
</th>
<th >
Description
</th>
<th >
Group
</th>
<th >
Data
</th>
</tr>
</thead>
<tbody>
<tr *cdkVirtualFor ="let data of address_obj_data_holder | filter:searchAddr">
<td >
{{data.name}}
</td>
<td >
{{data.description}}
</td>
<td >
{{data.group}}
</td>
<td >
{{data.data}}
</td>
</tr>
</tbody>
</table>
</div>
</cdk-virtual-scroll-viewport>
If I do like this, table header also scrolls when I scrolls down, and If I do like,
<cdk-virtual-scroll-viewport [itemSize] = "20">
<div class="result_table">
<table class="dataframe" border="1">
<thead>
<tr>
<th style="width: 20% !important;">
Name
</th>
<th style="width: 40% !important;">
Description
</th>
<th style="width: 20% !important;">
Group
</th>
<th style="width: 20% !important;">
Data
</th>
</tr>
</thead>
<tbody>
<tr *cdkVirtualFor ="let data of address_obj_data_holder | filter:searchAddr">
<td style="width: 20% !important;">
{{data.name}}
</td>
<td style="width: 40% !important;">
{{data.description}}
</td>
<td style="width: 20% !important;">
{{data.group}}
</td>
<td style="width: 20% !important;">
{{data.data}}
</td>
</tr>
</tbody>
</table>
</div>
</cdk-virtual-scroll-viewport>
width of header and tbody is slightly different both are not in same width as we have scroll in below body alone. Can some one help me to fix this alignment issue.
If you are looking to make the header sticky of table and you are using cdk-virtual-scroll-viewport, then try this:
table { overflow: auto; }
thead { position: sticky; top: 0; }

table content are exceeding in Card

Would like to ask if there is a solution for this. The table contents are exceeding in card. See screenshot below:
However, if I un-collapse the sidebar the view is fine. See screenshot below
Some of the page links are fine. some are not. Here is my code for td
#foreach($mfo as $row)
<tr style="font-size: 10.5pt;">
<td style="overflow-wrap: break-word;">{{$row->form_type}}</td>
<td style="overflow-wrap: break-word;">{{$row->dept_name}}</td>
<td style="overflow-wrap: break-word;">{{$row->function_name}}</td>
<td style="overflow-wrap: break-word;">{{$row->role}}</td>
<td style="overflow-wrap: break-word;">{!! $row->mfo_desc !!}</td>
<td style="overflow-wrap: break-word;">{!! $row->success_indicator_desc !!}</td>
<td>{!! $row->remarks !!}
<td>
Edit
<a href="#" class="btn btn-danger btn-sm"
data-mymfoid="{{$row->id}}" data-toggle="modal" data-target="#deletemfo">Delete</a>
</td>
</tr>
#endforeach
It's simply too much text in your table.
A wider screen could solve the issue (if you haven't got a max-width on the table or parent container).
If you can shorten the text in the table head that could help.
You might be able to decrease your font size as well.
Here is the solution on how I fixed it. However, I think it is not based on a good practice.
<table class="table table-striped" style="width: 100%; table-layout: fixed;">
<thead>
<tr>
<th style="width: 7%;">FORM TYPE</th>
<th style="width: 10%">DEPT NAME</th>
<th style="width: 13%;">FUNCTION NAME</th>
<th style="width: 10%;">ROLE NAME</th>
<th style="width: 20%">ORGANIZATIONAL OUTCOMES/KEY RESULTS AREA</th>
<th style="width: 20%">QUALITY + OBJECTIVES
(TARGETS + MEASURES)</th>
<th style="width: 20%">REMARKS</th>
<th style="width: 10%">ACTIONS</th>
</tr>
</thead>
<tbody>
#foreach($mfo as $row)
<tr style="font-size: 10.5pt;">
<td style="overflow-wrap: break-word;">{{$row->form_type}}</td>
<td style="overflow-wrap: break-word;">{{$row->dept_name}}</td>
<td style="overflow-wrap: break-word;">{{$row->function_name}}</td>
<td style="overflow-wrap: break-word;">{{$row->role}}</td>
<td style="overflow-wrap: break-word;">{!! $row->mfo_desc !!}</td>
<td style="overflow-wrap: break-word;">{!! $row->success_indicator_desc !!}</td>
<td>{!! $row->remarks !!}
<td>
Edit
<a href="#" class="btn btn-danger btn-sm"
data-mymfoid="{{$row->id}}" data-toggle="modal" data-target="#deletemfo">Delete</a>
</td>
</tr>
#endforeach
</tbody>
</table>
Notes:
In table class, I added a width=100%; table-layout: fixed;
Fixed width for each tag with a total of 110%

Not able to properly align table in Angular 2 - unwanted white space to the right

I am making a table in Angular 2. I have 4 columns, but after the last column unwanted white space to the right. I am using bootstrap as well.
The below given is the HTML class
<div class="panel panel-default">
<div class="panel-heading">User information</div>
<div class = 'data-table'>
<table style="width:60px" class="text-center" header-class="'text-center'" class="table table-bordered" [mfData]="data" #mf="mfDataTable" [mfRowsOnPage]="10">
<thead>
<tr>
<th style="width: 10%"></th>
<th style="width: 10%">
<mfDefaultSorter by="name">Name</mfDefaultSorter>
</th>
<th style="width: 10%">
<mfDefaultSorter by="email">Email</mfDefaultSorter>
</th>
<th style="width: 10%">
<mfDefaultSorter by="age">Age</mfDefaultSorter>
</th>
<th style="width: 10%">
<mfDefaultSorter by="city">City</mfDefaultSorter>
</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of mf.data">
<td>
<button class="btn btn-danger" title="remove">
<span class="glyphicon glyphicon-remove"></span>
</button>
</td>
<td>"AJ"</td>
<td>"AJ"</td>
<td class="text-right">"AJ"</td>
<td>"AJ"</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">
<mfBootstrapPaginator [rowsOnPageSet]="[5,10,15]"></mfBootstrapPaginator>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
Please see the screenshot of the page:
As denoted in the screenshot, I have marked in yellow the white space to the right and a small column like space at the bottom. how to remove those to get a proper table?
You are using 60px width and 10% on each <th> try to change this to 100% width and 20% on each cell.
<div class="panel panel-default">
<div class="panel-heading">User information</div>
<div class = 'data-table'>
<table style="width:100%" class="text-center" header-class="'text-center'" class="table table-bordered" [mfData]="data" #mf="mfDataTable" [mfRowsOnPage]="10">
<thead>
<tr>
<th style="width: 20%"></th>
<th style="width: 20%">
<mfDefaultSorter by="name">Name</mfDefaultSorter>
</th>
<th style="width: 20%">
<mfDefaultSorter by="email">Email</mfDefaultSorter>
</th>
<th style="width: 20%">
<mfDefaultSorter by="age">Age</mfDefaultSorter>
</th>
<th style="width: 20%">
<mfDefaultSorter by="city">City</mfDefaultSorter>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3">
<mfBootstrapPaginator [rowsOnPageSet]="[5,10,15]"></mfBootstrapPaginator>
</td>
</tr>
</tfoot>
<tbody>
<tr *ngFor="let item of mf.data">
<td>
<button class="btn btn-danger" title="remove">
<span class="glyphicon glyphicon-remove"></span>
</button>
</td>
<td>"AJ"</td>
<td>"AJ"</td>
<td class="text-right">"AJ"</td>
<td>"AJ"</td>
</tr>
</tbody>
</table>
</div>
</div>