Suppose I want to create a table with php-excel or laravel-excel that should has the following structure:
<table>
<thead>
<th>Column A</th>
<th>Column B</th>
</thead>
<tbody>
<tr>
<td>value 1</td>
<td>
<table>
<thead>
<th>neste column 1</th>
<th>nest column 2</th>
</thead>
<tbody>
<tr>
<td>nested value 1</td>
<td>nested value 2</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
I searched a lot and it seems that excel doesn't support nested table.
If it is possible, how we can do that?
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'm getting json data but I can't list it in datatable
Controller File
public function index()
{
$data = Http::get('https://jsonplaceholder.typicode.com/posts');
return view('frontend.default.index', ['data'=> $data->json()]);
}
View File
<table id="table_id" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
#foreach ($data as $key => $value)
<tr>
<td>
{{$value->title}} // not working
</td>
<td>Row 1 Data 2</td>
</tr>
#endforeach
</tbody>
</table>
The data you pull from json comes as an array. You are trying to print as an object while you print.
Solution
#foreach ($data as $key => $value)
<tr>
<td>
{{$value['title']}} // not working
</td>
<td>Row 1 Data 2</td>
</tr>
#endforeach
basically you use JSON data types for ajax since they cannot pass array or object data without JSON but when you are directly printing the value in the view then you do not need to convert the data to JSON. here is how you can use it.
public function index()
{
$data = Http::get('https://jsonplaceholder.typicode.com/posts');
//check if data is being received
if(!$data)
return back()->with('error', 'no data received');
return view('frontend.default.index', compact('data'));
}
and in the front end......
<table id="table_id" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
#foreach ($data as $key => $value)
<tr>
<td>
{{$value->title}}
</td>
<td>Row 1 Data 2</td>
</tr>
#endforeach
</tbody>
</table>
or
<table id="table_id" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
#foreach ($data as $key => $value)
<tr>
<td>
{{$value['title']}}
</td>
<td>Row 1 Data 2</td>
</tr>
#endforeach
</tbody>
</table>
I have the following html code :
<table>
<tbody>
<tr>
<th >operatore</th>
<td>3</td>
<td>4</td>
<td>5</td>
<tr/>
<tr>
<th >operatore</th>
<td>6</td>
<td>7</td>
<td>8</td>
<tr/>
</tbody>
</table>
I would like to insert the following tags after the TABLE tag:
<thead>
<tr>
<th >Nome IT</th>
<th >a</th>
<th >b</th>
<th >c</th>
</tr>
</thead>
so I'd like to get:
<table>
<thead>
<tr>
<th >Nome IT</th>
<th >a</th>
<th >b</th>
<th >c</th>
</tr>
</thead>
<tbody>
<tr>
.....
I created the following code for THEAD and succeeded:
$thead = $dom_ods->createElement("thead", "");
$ods2_tmp->insertBefore($thead, $ods2_tmp->firstChild);
$dom_ods->saveHTML();
while I can't for the others, how can I proceed?
I got a huge dataset with around 39 columns. Now the datatable exceeds the display area of the browser.
No problem with rows is they are listed based on pagination. Is there any wrapping property to datatables? I want to display all columns in the same browser space
My datatable columns are
<table id='datatable' class="ui celled table" style='width:100%'>
<thead>
<tr>
<th>DeviceID</th>
<th>AppID</th>
<th>IsFingerprint</th>
<th>CurrentDate</th>
<th>IsSDCard</th>
<th>NetworkType</th>
<th>TotalRAM</th>
<th>AvailInternal</th>
<th>AvailExternal</th>
<th>TotalInternal</th>
<th>TotalExternal</th>
<th>Activity</th>
<th>Package</th>
<th>AppStore</th>
<th>AppName</th>
<th>AppVersion</th>
<th>AppVersionCode</th>
<th>BatteryCharge</th>
<th>IsCharging</th>
<th>Manufacturer</th>
<th>Model</th>
<th>OSCodename</th>
<th>OSVersion</th>
<th>Product</th>
<th>Device</th>
<th>Board</th>
<th>Hardware</th>
<th>Rooted</th>
<th>Brand</th>
<th>Host</th>
<th>Time</th>
<th>User</th>
<th>ScreenResolution</th>
<th>ScreenDensity</th>
<th>ScreenSize</th>
<th>Country</th>
<th>Carrier</th>
<th>ActiveTraffic</th>
<th>AppUsage</th>
<th>Image</th>
</tr>
</thead>
<tfoot>
<tr>
<th>DeviceID</th>
<th>AppID</th>
<th>IsFingerprint</th>
<th>CurrentDate</th>
<th>IsSDCard</th>
<th>NetworkType</th>
<th>TotalRAM</th>
<th>AvailInternal</th>
<th>AvailExternal</th>
<th>TotalInternal</th>
<th>TotalExternal</th>
<th>Activity</th>
<th>Package</th>
<th>AppStore</th>
<th>AppName</th>
<th>AppVersion</th>
<th>AppVersionCode</th>
<th>BatteryCharge</th>
<th>IsCharging</th>
<th>Manufacturer</th>
<th>Model</th>
<th>OSCodename</th>
<th>OSVersion</th>
<th>Product</th>
<th>Device</th>
<th>Board</th>
<th>Hardware</th>
<th>Rooted</th>
<th>Brand</th>
<th>Host</th>
<th>Time</th>
<th>User</th>
<th>ScreenResolution</th>
<th>ScreenDensity</th>
<th>ScreenSize</th>
<th>Country</th>
<th>Carrier</th>
<th>ActiveTraffic</th>
<th>AppUsage</th>
<th>Image</th>
</tr>
</tfoot>
</table>
I use AJAX to load data from my PHP API endpoint and it works fine.
Is there any way to merge cells like AppName, AppPackage, AppVersion, AppVersionCode comes under App cell
I have a requirement to output a table using Smarty and then have the user select a row to take them to another page.
I can display the table fine:
{html_table cols="Job Title,Salary,Sector,Location" loop=$results}
which gives:
<table border="1">
<thead>
<tr>
<th>Job Title</th>
<th>Salary</th>
<th>Sector</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dog walker</td>
<td>20000</td>
<td>None</td>
<td>London</td>
</tr>
<tr>
<td>F1 Driver</td>
<td>10000000</td>
<td>Financial Services</td>
<td>Scotland</td>
</tr>
</tbody>
</table>
but I am not sure if it is possible to add a hyperlink as an additional column to the table that links to a page using a hidden id.
So I would want something link this:
<table border="1">
<thead>
<tr>
<th>Job Title</th>
<th>Salary</th>
<th>Sector</th>
<th>Location</th>
<th>Apply</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dog walker</td>
<td>20000</td>
<td>None</td>
<td>London</td>
<td>Apply</td>
</tr>
<tr>
<td>F1 Driver</td>
<td>10000000</td>
<td>Financial Services</td>
<td>Scotland</td>
<td>Apply</td>
</tr>
</tbody>
</table>
Is that possible?
Yes, but you need to modify the $results array before you pass it to Smarty so that the 4th element of each row contains the link as a string. There's no way to have {html_table} generate the link for you.