PrimeNg truncate cell content in scrollable table - primeng

I need to create a scrollable table setting the fixed width of each column. I tried to set [scrollable]="true" scrollDirection="horizontal" and to fix the width for each column but it's not shown correctly. The number of columns is not fixed so I can't use percentage width. I'm trying in this way:
<p-table [value]="result" [columns]="columns" [(selection)]="selectedResults"
[scrollable]="true">
<ng-template pTemplate="header" let-columns>
<tr>
<th style="min-width: 50px; max-width: 50px;">
<p-tableHeaderCheckbox></p-tableHeaderCheckbox>
</th>
<ng-template ngFor let-col [ngForOf]="columns">
<th style="min-width: 120px; max-width: 120px;">
<span class="label-ellipsis">{{col.header | translate}}</span>
</th>
</ng-template>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData>
<tr [pSelectableRow]="rowData">
<td style="min-width: 50px; max-width: 50px;">
<p-tableCheckbox [value]="rowData"></p-tableCheckbox>
</td>
<ng-template ngFor let-col [ngForOf]="columns">
<span class="label-ellipsis">{{rowData[col.field]}}</span>
</ng-template>
</tr>
</ng-template>
</p-table>
My first question is: is the right way to set column width? Is it necessary to use min-width and max-width?
css class is:
label-ellipsis {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
The problem is that css ruls works for table header but not for cell. The overflow hiddens the cell content, so the result is:
I found various solutions that suggest to use resizable column but I need to set fixed width. Is there a way to truncate the content of the cell?

Related

How to change table cell background color based on cell value in using directive in Angularjs

I have a table that displays data for health insurance allocation to a beneficiary. I need to add a condition that checks for values whose usage by a a member is more than 70% of the initial allocation and in such a scenario, the cell displaying that value background changes on mouse hover.
So far, I have only been able to fetch all data from my back-end service and render it on the table.
My code implementation is as follows:
<div class="panel-body">
<div class="form-group col-sm-12" style="max-height: 400px; overflow-y: auto;">
<table class="table table-bordered table-striped table-responsive input-sm">
<thead>
<tr>
<th>
<div class="th"><b>HEALTH BASKET</b></div>
</th>
<th >
<div class="th"><b>ALLOCATION</b></div>
</th>
<th >
<div class="th"><b>USAGE</b></div>
</th>
<th >
<div class="th"><b>BALANCE</b></div>
</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="voucher in vouchers">
<td>{{voucher.voucherName}}</td>
<td>{{voucher.value}}</td>
<td >{{voucher.used}}</td>
<td>{{voucher.amountRemaining}}</td>
</tr>
</tbody>
</table>
</div>
</div>
Any idea of how this can be implemented using the Angular directives?
You need to make use of the directives ng-mouseover, ng-mouseleave and ng-class
In your <tbody>:
<tbody>
<tr data-ng-repeat="voucher in vouchers" ng-class="{'usage-exceeded': usageExceeded}" ng-mouseover="checkUsage(voucher)" ng-mouseleave="usageExceeded = false">
<td>{{voucher.voucherName}}</td>
<td>{{voucher.value}}</td>
<td >{{voucher.used}}</td>
<td>{{voucher.amountRemaining}}</td>
</tr>
</tbody>
And inside the controller function:
$scope.checkUsage = function (voucher) {
// add the logic to set the $scope.usageExceeded as true, change this logic as per
// your condition
if ((voucher.used / voucher.value) * 100 > 70) {
$scope.usageExceeded = true;
}
};
Now, add the css class usage-exceeded inside your css which will change the background color.
.usage-exceeded {
background-color: red;
}

How to click on row element by text instead of xpath using selenium 2 robotframework

<div class="dataTables_scroll">
<div class="dataTables_scrollHead ui-state-default" style="overflow: hidden; position: relative; border: 0px none; width: 100%;">
<div class="dataTables_scrollBody" style="position: relative; overflow: auto; width: 100%;">
<table id="DataTables_Table_4" class="dataTable no-footer" role="grid" aria-describedby="DataTables_Table_4_info" style="width: 100%;">
<thead>
<tbody>
<tr class="odd" role="row">
<tr class="even" role="row">
<td class="center-col multiRowSelect sorting_1">
<td>GROUP4</td>
<td class=" center-col">Enterprise Open</td>
<td class=" center-col">0</td>
</tr>
</tbody>
</table>
</div>
Are you absolutely sure you don't like xpath for that? It is awfully powerful and can in fact very well be used to find by text:
Click Element xpath=//*[contains(text(),"GROUP")]/parent::tr

How to make <td> responsive

I am doing responsive mail and I need to make responsive td in table (without class or using media-query).
Simply - I need on small devices rank the td under them.
<table align="center" cellspacing="0" cellpadding="0" border="0" bgcolor="fff" style="width:100%; background-color: #fff; max-width:600px;">
<tr>
<td><img src="pic" /></td>
<td><a href="https://blahblah2.com/><img src="pic" /></a></td>
<td><a href="http://www.blahblah3.com/><img src="pic" /></a></td>
<td><a href="http://www.blahblah4.com/><img src="pic" /></a></td>
</tr>
</table>
You can try display:inline-block for every column in your table. It will make the columns shift below each column when width of the screen decreases.
As you have mentioned that you don't need class so m writing the inline style for each column. Try this code :
<table align="center" cellspacing="0" cellpadding="0" border="0" bgcolor="fff" style="width: 100%;
background-color: #fff; max-width: 600px;">
<tr>
<td style="display: inline-block; padding: 5px;">
<p>
hellohello</p>
</td>
<td style="display: inline-block; padding: 5px;">
<p>
hellohello</p>
</td>
<td style="display: inline-block; padding: 5px;">
<p>
hellohello</p>
</td>
<td style="display: inline-block; padding: 5px;">
<p>
hellohello</p>
</td>
</tr>
</table>
Fiddle here
You can create a media query to force all the td elements to drop below each other at a certain screen width. This ensures they all become vertical-aligned at the same time. It also preserves the table's horizontal-aligned print format if you are generating a report for printing.
#media only screen and (min-width: 0px) and (max-width: 700px) {
td {
display:inline-block;
padding:5px;
width:100%;
}
}

How to get a fixed columnwidth with ngtable?

I am getting my head around the ngtable. Just one question, how can I make the columns fixed width? In this sample the account and adviser column have variable width when going to the next page.
This is the html:
<table ng-table="tableParams" template-pagination="custom/pager" class="table">
<tr ng-repeat="account in $data | filter:accountName | filter:key" class="orders tablerow">
<td data-title="'ID'" sortable="'account.accountId.key'">
{{account.account.accountId.key}}
</td>
<td data-title="'Account'" sortable="'account.accountName'">
{{account.account.accountName}}
</td>
<td data-title="'Adviser'" sortable="'account.adviser.key'">
{{account.account.adviser.key}}
</td>
<td data-title="'Product'" sortable="'account.productName'">
{{account.account.productName}}
</td>
<td data-title="'Status'" sortable="'minOpenOrderState'">
{{account.minOpenOrderState}}
</td>
</tr>
</table>
Plunkr:http://plnkr.co/edit/vPQeVx?p=info
just add css for "td"
td{
width:20%;
float:left;
word-wrap:break-word;
}
Accepted answer is working perfectly, but it does not cover the case when most of the columns width does not matter, but 1-2 columns should have a fixed width (or at least not be squeezed)
One work-around is to force the width of a column by defining a fixed-width content. Something like this:
<td title="'TheTitle'" sortable="'PassedStr'">
<div style="width:120px">
<b>{{item.SomeCol}}</b>
<span ng-show="item.ErrorMessage">
{{item.OtherCol}}
</span>
</div>
</td>

Extra spacing for TD in IE7

Below is mycode. Problem is whenever i use float element whose width is more than td:ed(1). It takes extra space. I appreciate your suggestion.
<table style="background:#ff0;border:1px solid #ccc; width:100%">
<tbody>
<tr>
<td style="width:30px; border-right:1px solid #ccc; overflow:hidden">1</td>
<td>Test</td>
</tr>
<tr >
<td colspan="2"><input type="text" /></td>
</tr>
</tbody>
</table>
Below are screen shots of .
Mozilla
IE7
I found answer for this.
For IE i added css property
table
{
table-layout:fixed;
}
This solves my problem.
Thanks.

Resources