i have some problems with my table i have this table for egs
<tr style="">
<td>1</td>
<td>item 1</td>
</tr>
<tr style="">
<td>1.1</td>
<td>item 1.1</td>
</tr>
<tr style="">
<td>1.2</td>
<td>item 1.2</td>
</tr>
<tr style="">
<td>1.1.1</td>
<td>item 1.1.1</td>
</tr>
i use jquery ui sortable but the problem is that if i want to move the item 1 the item1.2 and item 1.1.1 will also follow something like a group
fiddle link http://jsfiddle.net/kN2XL/
You should have a look at nestedSortable to implement this kind of functionality. Example
Unfortuately, you will however need to change your html from tables into a hierarchy, like <ul> <li> etc.
Related
I only know the basics of scraping webpages using php simple html dom. The webpage has several tables on it, all with the same classes - so nothing unique to each table.
<table class="table">
<tr>
<td>item 1</td>
<td>item 2</td>
<td>item 3</td>
</tr>
</table>
<table class="table">
<tr>
<td>item 4</td>
<td>item 5</td>
<td>item 6</td>
</tr>
</table>
<table class="table">
<tr>
<td>item 7</td>
<td>item 8</td>
<td>item 9</td>
</tr>
</table>
The code I have is working, however it's returning data from ALL tables, and I only want data from the first table. I'm using the following to find the rows of data :
$d1s = $dom->find('table.table tr');
I'm assuming it's a simple error I've made. Can anyone help ?
I am trying to print this table in TCPDF, the table is rendering fine but it is totally skipping the <tr> row with colspan , this happens to the only row that has the first <td colspan="8"> cell with a colspan.
This is the html table tha:
<table style="font-size:7px;line-height:16px;border:none;" dir="ltr" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="width:17%;"></td>
<td>YTD</td>
<td>2019</td>
<td>2018</td>
<td>2017</td>
<td>2016</td>
<td>2015</td>
<td>2014</td>
</tr>
<tr>
<td>Portfolio</td>
<td>-3.63%</td>
<td>14.51%</td>
<td>-5.11%</td>
<td>11.16%</td>
<td>8.48%</td>
<td>-2.13%</td>
<td>2.45%</td>
</tr>
<tr>
<td>Benchmark </td>
<td>-1.64%</td>
<td>9.78%</td>
<td>-3.84%</td>
<td>7.37%</td>
<td>2.92%</td>
<td>-2.66%</td>
<td>0.08%</td>
</tr>
<tr>
<td colspan="8">Morningstar USD Cautious Allocation</td>
</tr>
<tr>
<td></td>
<td>
<p class="double-line">Annualised Return</p>
</td>
<td>
<p class="double-line">Standard Deviation</p>
</td>
<td>
<p class="double-line">Sharpe Ratio</p>
</td>
<td colspan="4"></td>
</tr>
<tr>
<td>Portfolio</td>
<td>4.45%</td>
<td>5.72%</td>
<td>0.78</td>
<td colspan="4"></td>
</tr>
<tr>
<td>Benchmark </td>
<td>2.08%</td>
<td>2.44%</td>
<td>0.85</td>
<td colspan="4"></td>
</tr>
</tbody>
</table>
output on the browser page is fine (see image)
but output on the PDF removes that row completely:
The issue is solved, the problem was not in TCPDF, It was the table not having a proper closing tag for the row </tr> . The table above was coming from a custom field storing it in the DB of a wordpress site. Since the html is generated through a php code I had minor coding error that I forgot to close the row with </tr>. However when viewing the html content in a wordpress WYSWIG editor , it adds the self closing tags. When you debugging it on the browser page also most browsers add auto closing tags. These made me think that the html structure of the table is good and should be an issue with TCPDF. After checking the HTML in the database I finally figured out the table row wasn't closing properly.
Hopefully this will help someone having a similar issue in the future.
Is there a way to display two HTML tables side by side in a PDF-document generated with TCPDF?
I tried inline-CSS but neither float: left nor display: inline-block works.
I am using version 6.2.12.
You should try merging two table inside another parent table like:
<table>
<tr>
<td>
<table>
<tr>
<td>data that you want to display left</td>
</tr>
</table>
</td>
<td>
<table>
<tr>
<td>data that you want to display right</td>
</tr>
</table>
</td>
</tr>
</table>
add this html to variable and then pass that variable into tcpdf menthod writeHTML().
I am able to get the coding of a website with file_get_contents but I want to be able to get certain values out of the html. This piece of code is always the same but the value between the html tag changes from time to time. This is the HTML Code:
<div class="cheapest-bins">
<h3>Cheapest Live Buy Now</h3>
<table>
<tbody><tr>
<th>Console</th>
<th>Buy Now Price</th>
</tr>
<tr class=" active">
<td class="xb1">XB1</td>
<td>1,480,000</td>
</tr>
<tr class="">
<td class="ps4">PS4</td>
<td>1,590,000</td>
</tr>
<tr class="">
<td class="x360">360</td>
<td>---</td>
</tr>
<tr class="">
<td class="ps3">PS3</td>
<td>2,800,000</td>
</tr>
</tbody></table>
</div>
How would I go about getting the: 1,480,000 .. 1,590,000 .. --- and 2,800,000?
short answer:
find a css selector library such as https://github.com/tj/php-selector
then you could grab all td:last-child elements/innerhtml
for your specific example you could just just
preg_match_all('#<td>(.*?)</td>#', $html, $matches);
How can I get the class of the table when clicking the tr?
This is my code
<table class='table1' border='1'>
<tr class='graph1'>
<td>Test1</td>
<td><a class='viewHistory'>View History<a></td>
</tr>
<tr class='graph2'>
<td>Test2</td>
<td><a class='viewHistory'>View History<a></td>
</tr>
<tr class='graph3'>
<td>Test3</td>
<td><a class='viewHistory'>View History<a></td>
</tr>
</table>
<table class='table2' border='1'>
<tr class='graph1-1'>
<td>Test1</td>
<td><a class='viewHistory'>View History<a></td>
</tr>
<tr class='graph2-1'>
<td>Test2</td>
<td><a class='viewHistory'>View History<a></td>
</tr>
<tr class='graph3-1'>
<td>Test3</td>
<td><a class='viewHistory'>View History<a></td>
</tr>
</table>
When I click on
<tr class='graph2'>
<td>Test2</td>
<td><a class='viewHistory'>View History<a></td>
</tr>
It should display 'table1'
or if I click on
<tr class='graph3-1'>
<td>Test3</td>
<td><a class='viewHistory'>View History<a></td>
</tr>
It should display: 'table2'
Take not that this is dynamic, its not only graph2 or graph3-1 will be clicked.
how would I do that using jquery?
Any help would be greatly appreciated and rewarded! Thanks!
I would use closest() to find the table parent. See also http://api.jquery.com/closest/
$('.viewHistory').click(function() {
var classname = $(this). closest('table').attr('class');
alert(classname);
}
jQuery('table tr').click(function(){
//this is set to the row's DOM element
jQuery(this).parent('table').attr('class');
});
See the jQuery.parent for details.
Never used it personally so not sure about this, but jQuery.closest may give better performance compared to jQuery.parent.
Also, please note that the following code sample will attach click event for any table row in the document, so you'd better add some specific class to your tables (say clickable_table and use it like this)
jQuery('.clickable_table tr').click(function(){
//this is set to the row's DOM element
jQuery(this).parent('table').attr('class');
});
You can use the .parent() function (if you want to click the a tag, use it twice)
and the .attr("class") to get the class. I think there is also a .class or something but not sure right now.