Primeng header misalign from body table - primeng-datatable

Having a scrollable table with a scrollHeight set and after that changing the scrollHeight, the scrollbar should be aligned with the table header automatically. The table data is not changed.
(I have a scrollable table with header in a resizable dialog, and when dialog resizes, the scrollHeight of the table changes accordingly, but the scrollbar of the table is not aligned to the new scrollHeight)
updating primeng to 7.1.4 version.
<p-table [columns]="cols" [value]="cars" scrollable="true" [scrollHeight]="scrollHeight">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
Correct display of the scrollbar on a scrollable table when changing the scrollHeight dynamically without chaning the data.

It seems to be an ongoing problem, there is a workaround here: https://github.com/primefaces/primeng/issues/5354. But still seems unsolved.
The workaround is to add these styles:
.ui-table-scrollable-header-box {
margin-right: 17px !important;
}
.ui-table-scrollable-body {
margin-right: 17px !important;
}

My workaround :
p-table {
cdk-virtual-scroll-viewport {
overflow-y: scroll !important;
}
}

Best solution which worked like charm for me:
.ui-table .ui-table-scrollable-body-table {
min-height: 1px !important;
}

In my case, if we add a width in header column than must add same width for body on that column
<p-table scrollHeight="calc(100vh - 280px)" [scrollable]="true" [paginator]="true" [rows]="100" [responsive]="true">
<ng-template pTemplate="header">
<tr>
<th style="width: 50px;"> Header One </th>
<th> Header Two </th>
<th> Header Three </th>
<th style="width: 150px;"> Header Four </th>
<th> Header Five </th>
</tr>
</ng-template>
<ng-template pTemplate="body">
<tr>
<td style="width: 50px;"> Body One </td>
<td> Body Two </td>
<td> Body Three </td>
<td style="width: 150px;"> Body Four </td>
<td> Body Five </td>
</tr>
</ng-template>
</p-table>

I've managed to solve this issue by doing the following:
1- add display: grid !important; to .p-datatable css class
2- add display: block; to .p-datatable>.p-datatable-thead>tr>th and .p-datatable>.p-datatable-tbody>tr>th
at the end you will have some structure like this:
.p-datatable {
.p-datatable-thead{
>tr{
>th{
display: block;
}
}
}
.p-datatable-tbody{
>tr{
>th{
display: block;
}
}
}}

Related

TinyMCE paste from excel

I have a problem with TinyMCE editor which I cannot resolve.
If I copy a table from Excel and paste it into the editor it loses the formatting. I have set up extended_valid_elements as follows...
extended_valid_elements:"a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],table[style|class|border=2|width|cellspacing|cellpadding|bgcolor],colgroup,col[style|width],tbody,tr[style|class],td[style|class|colspan|rowspan|width|height|background|span|padding],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style|font-family|color]"
The HTML that is saved into the MySQL field is as follows
From Excel ...
<table style="border-collapse: collapse; width: 242pt;" border="2" width="322">
<tbody>
<tr style="height: 14.25pt;">
<td style="height: 14.25pt; width: 105pt;" width="140">Test</td>
<td style="width: 104pt;" width="138"></td>
<td style="width: 33pt;" width="44"> </td>
</tr>
</tbody>
</table>
From Word ...
<table style="width: 242.0pt; border-collapse: collapse;" border="2" width="0">
<tbody>
<tr style="height: 14.25pt;">
<td style="width: 105.0pt; padding: 0cm 5.4pt 0cm 5.4pt; height: 14.25pt;" width="140">
<p style="margin-bottom: .0001pt; line-height: normal;"><span style="font-size: 10.0pt; font-family: 'Arial',sans-serif; color: black;">Test</span></p>
</td>
<td style="width: 104.0pt; padding: 0cm 5.4pt 0cm 5.4pt; height: 14.25pt;" width="139"></td>
<td style="width: 33.0pt; background: #92D050; padding: 0cm 5.4pt 0cm 5.4pt; height: 14.25pt;" width="44">
<p style="margin-bottom: .0001pt; line-height: normal;"><span style="font-size: 10.0pt; font-family: 'Arial',sans-serif; color: black;"> </span></p>
</td>
</tr>
</tbody>
</table>
How can I make this work from excel without having to go through word first?
It would appear I have to use power paste which is a paid-for option ... I have a call setup with their sales team to see how much it will cost! Fingers crossed.

Multiple CustomJSHovers mapped to one field Bokeh

My Bokeh version is 2.3.1. I'm able to use the CustomJSHover to specify some javascript to execute on hover, with the input being a field (from a column data source). However, I'm trying to map different CustomJSHover's to the same field, and specify them differently in the HTML. An example snippet of what I have is
customjs = CustomJSHover(code="""///do some javascript here on the value var.""")
hover_points = HoverTool(tooltips="""
<div $x{custom} id=$index style="font-size:12px; font-family:arial; color:white; background:black; padding:10px;">
<div>
<span style="font-weight:bold;">Name:</span>
<span>#input_x{custom}</span>
</div>
""",
formatters={
'#input_x' :customjs
},
point_policy='snap_to_data')
This works great, but I want to have multiple custom formaters on input_x. If I try something like this
c1 = CustomJSHover(code="console.log(1);")
c2 = CustomJSHover(code="console.log(2);")
hover_highlight_line = HoverTool(tooltips="""
<div style="font-size:12px; font-family:arial; color:white; background:black; padding:10px;">
<table>
<tr>
<th style="text-align: center;">1</th>
<th style="text-align: center;">2</th>
</tr>
<tr>
<td style="padding:5px;">#input_x{c2}</td>
<td style="padding:5px;">#input_x{c1}</td>
</tr>
</table>
</div>
""",
formatters= {
'#input_x':c1,
'#input_x':c2
},
I only get the console log for c2. Is this possible to achieve? Thanks.
After sleeping on it, I finally found out how to do this.
Within the bracket, you can map a prefix to a formatter. This is in the docs, but the doc's don't tell you how to use it. Within the CustomJSCode argument, you can access this prefix (or if you want just specify the name) with the format variable.
c1 = CustomJSHover(code="""
if(format == 'agg'){ return //do something with agg}
else if(format == 'mean'){return //do something to get the mean}
""")
hover_highlight_line = HoverTool(tooltips="""
<div style="font-size:12px; font-family:arial; color:white; background:black; padding:10px;">
<table>
<tr>
<th style="text-align: center;">1</th>
<th style="text-align: center;">2</th>
</tr>
<tr>
<td style="padding:5px;">#input_x{agg}</td>
<td style="padding:5px;">#input_x{mean}</td>
</tr>
</table>
</div>
""",
formatters= {
'#input_x':c1,
},
If there is a better way to do this, please post an answer. Thanks.

HTML table scraping - table object returned as 1 big cell instead of separate elements

I've been working on a webpage scraping program from within excel VBA (with lots of help from this forum).
I've gotten stuck at a table which shows a single row, which I need to automate clicking. I used the same method for a similar table earlier in the process and that worked fine:
setting the HTML table to IEtable object
using ietable.rows(1).click
This table however, returns as 1 cell containing the values of all the separate elements I see on the webpage and the .click function doesn't work.
This is the HTML code for the table I am trying to access:
<table id="tblPatientList" class="tblTabBody" style="height: 143px; width: 653px;" cellspacing="2" cellpadding="0">
<tbody>
<tr style="height: 100%; width: 100%;">
<td style="width: 649px; height: 100%;">
<div id="divPatientList" style="overflow: auto; width: 100%; height: 100%; background-color: white;">
<table id="dgrPatients" class="tblpat" style="border-width: 0px; width: 100%; border-collapse: collapse;" border="0" rules="all" cellspacing="0" cellpadding="1">
<tbody>
<tr class="headerBlue">
<td style="width: 5%;"> </td>
<td style="width: 15%;">Hosp No.</td>
<td style="width: 15%;">Surname</td>
<td style="width: 15%;">Forename</td>
<td style="width: 10%;">DOB</td>
<td style="width: 2%;">Sex</td>
<td style="width: 10%;">NHS Number</td>
<td style="width: 25%;">Address</td>
<td class="screenOnlyOutput" style="width: 5%;" align="center">List</td>
</tr>
<tr class="even" style="color: red;">
<td align="center"> </td>
<td><strong>12345678</strong></td>
<td>ANONYMOUS FIRST NAME</td>
<td>ANONYMOUS LAST NAME</td>
<td>dd/mm/yyyy</td>
<td align="center">M</td>
<td>123 456 7890 <img style="cursor: hand; vertical-align: middle; border: 0px;" title="Number present and verified" src="/icedesktop/dotnet/icedesktop/images/tick.gif" /></td>
<td>ANONYMOUS ADDRESS</td>
<td class="screenOnlyOutput" align="center"><input id="dgrPatients_ctl02_chkAddOrRemove" style="border: 0px; height: 12px;" name="dgrPatients$ctl02$chkAddOrRemove" type="checkbox" /></td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
This table always only returns 2 rows - a header and 1 data row. I try to click it with:
Set ieTbl = ieDoc.Document.frames(0).Document.all.tblPatientList
If Not ieTbl Is Nothing Then
ieTbl.Rows(1).Click
Set ieTbl = Nothing
End If
When I examine the ietable object in the immediate window, it only has 1 row and 1 column, containing all the separate cells on the html page in 1 cell in the ietbl object.
Why is it doing this?

Get data from inside a div/table

#QHarr answered my question here Get the value inside Nested Tables and Divs using VBA regarding the values inside the nested tables and it worked great. Now I realize that not all the data are getting pulled. Here is what I thought my HTML was:
<body style="BORDER: 0px; MARGIN: 0px; PADDING: 0px">
<DIV style="HEIGHT:100%;WIDTH:100%;" class="ap">
<TABLE CELLSPACING="0" CELLPADDING="0">
<TR>
// This TD was solved by #QHarr
<TD ID="oReportCell">
Some tables and values. #QHarr already solved this part
</TD>
</TR>
</TABLE>
</DIV>
</body>
But when I realized that not all the data were pulling I checked the HTML I found out that not all the data are inside the ID="oReportCell"
So, HTML looks like this:
<body style="BORDER: 0px; MARGIN: 0px; PADDING: 0px">
<DIV style="HEIGHT:100%;WIDTH:100%;" class="ap">
<TABLE CELLSPACING="0" CELLPADDING="0">
<TR>
// This TD was solved by #QHarr
<TD ID="oReportCell">
Some tables and values. #QHarr already solved this part
</TD>
</TR>
</TABLE>
</DIV>
<DIV style="HEIGHT:100%;WIDTH:100%;" class="ap">
<TABLE CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ID="oReportCell">
Some tables and values.
</TD>
</TR>
</TABLE>
<DIV style="HEIGHT:100%;WIDTH:100%;" class="ap">
<TABLE CELLSPACING="0" CELLPADDING="0">
<TR>
<TD ID="oReportCell">
Some tables and values.
</TD>
</TR>
</TABLE>
</body>
They are 14 of Class="ap", and when the code is executed sometime it gets the first one. Sometime the second and so on. It doesn't get all the value.
I need to get everything that is inside class ="a92" and class="a69"
here is the full html:
I can't use pastebin due to the size of the file:
enter link description here
here is one of the .ap
enter link description here

finding the direct child of a tag in watir

I have a table containing multiple columns in which the data is populated from a database. The columns can have drop-downs, text-fields, check-boxes along with simple text. I need to write down a function which will essentially return the data present in a table column.
Here's an example as to how the tags are named in the web page. [Credits to w3schools for the CSS for the tables].
<html>
<head>
<style type="text/css">
#customers
{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
width:100%;
border-collapse:collapse;
}
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
}
#customers th
{
font-size:1.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
}
#customers tr.alt td
{
color:#000000;
background-color:#EAF2D3;
}
</style>
</head>
<body>
<table id="customers">
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr class="data-row">
<td id="customers:0:company">Alfreds Futterkiste</td>
<td id="customers:0:contact">Maria Anders</td>
<td id="customers:0:chooseCountry">
<select id="customers:0:country">
<option>Germany</option>
<option>Sweden</option>
<option>Mexico</option>
</select>
</td>
</tr>
<tr class="data-row alt">
<td id="customers:1:company">Berglunds snabbköp</td>
<td id="customers:1:contact">Christina Berglund</td>
<td id="customers:1:chooseCountry">
<select id="customers:1:country">
<option>Germany</option>
<option selected="selected">Sweden</option>
<option>Mexico</option>
</select>
</td>
</tr>
<tr class="data-row">
<td id="customers:2:company">Centro comercial Moctezuma</td>
<td id="customers:2:contact">Francisco Chang</td>
<td id="customers:2:chooseCountry">
<select id="customers:2:country">
<option>Germany</option>
<option>Sweden</option>
<option selected="selected">Mexico</option>
</select>
</td>
</tr>
</table>
</body>
</html>
Now, the algorithm which I use for determining all the values in the column say "Company" is
Determine the no of rows having class = or substring as "data-row".
Construct the string for getting the cell and iterating it from 0 to n-1
Use the text method to retrieve the text
Now, if I use this on a select_list, it returns all the options in the list. Thus, I was going to check whether the child of the tag is either a text-field or a drop-down
list and call their respective functions to get their values.
Is there a way where in Watir we can determine the child of a particular tag is a particular tag or not or is there some method similar to getAllChildNodes in JavaScript?
Sorry for being over-descriptive and thanks in advance for any possible solutions.
This is very simple, you just need to see whether a text_field or select_list exists:
require 'watir-webdriver'
b = Watir::Browser.start 'yourwebpage'
b.table.rows.each do |row|
row.cells.each do |cell|
if cell.text_field.exist?
puts cell.text_field.value
elsif cell.select_list.exist?
puts cell.select_list.selected_options
else
puts cell.text
end
end
end
b.close

Resources