admin管理员组文章数量:1400352
My problems are:
- When I click the print button, it shows the data by text not in table.
- I want to print data table depends on the current table show. means here is on the current page has list of all data and select option. When I select or filter table it still print all the data. The data here is collected from database.
- After logged in, why does the image for next page not show?
Here is my JavaScript:
<script lang='javascript'>
$(document).ready(function(){
$('#printPage').click(function(){
var data = '<input type="button" value="Print this page" onClick="window.print()">';
data += '<div id="div_print">';
data += $('#report').html();
data += '</div>';
myWindow=window.open('','','width=200,height=100');
myWindow.innerWidth = screen.width;
myWindow.innerHeight = screen.height;
myWindow.screenX = 0;
myWindow.screenY = 0;
myWindow.document.write(data);
myWindow.focus();
});
});
</script>
Blade template:
<tbody id="result">
@foreach($profiles as $profile)
<tr>
<td class="student_id" width="15%">{{$profile->student_id }}</td>
<td class="name" width="30%">{{$profile->student_name }}</td>
<td class="program" width="30%"> {{$profile->program }}</td>
<td class="faculty" width="25%">{{$profile->faculty }} </td>
</tr>
@endforeach
</tbody>
</table>
<p align="center"><button id="printPage">Print</button></p>
My problems are:
- When I click the print button, it shows the data by text not in table.
- I want to print data table depends on the current table show. means here is on the current page has list of all data and select option. When I select or filter table it still print all the data. The data here is collected from database.
- After logged in, why does the image for next page not show?
Here is my JavaScript:
<script lang='javascript'>
$(document).ready(function(){
$('#printPage').click(function(){
var data = '<input type="button" value="Print this page" onClick="window.print()">';
data += '<div id="div_print">';
data += $('#report').html();
data += '</div>';
myWindow=window.open('','','width=200,height=100');
myWindow.innerWidth = screen.width;
myWindow.innerHeight = screen.height;
myWindow.screenX = 0;
myWindow.screenY = 0;
myWindow.document.write(data);
myWindow.focus();
});
});
</script>
Blade template:
<tbody id="result">
@foreach($profiles as $profile)
<tr>
<td class="student_id" width="15%">{{$profile->student_id }}</td>
<td class="name" width="30%">{{$profile->student_name }}</td>
<td class="program" width="30%"> {{$profile->program }}</td>
<td class="faculty" width="25%">{{$profile->faculty }} </td>
</tr>
@endforeach
</tbody>
</table>
<p align="center"><button id="printPage">Print</button></p>
Share
Improve this question
edited Dec 10, 2015 at 7:45
Pᴇʜ
57.8k10 gold badges55 silver badges75 bronze badges
asked Dec 10, 2015 at 6:26
ariana roseariana rose
1111 gold badge2 silver badges13 bronze badges
5
- what do you want to print the data in? a pdf? or just to any source? – JGCW Commented Dec 10, 2015 at 6:42
- @GeethW could u help me, how to get parameter for print the data on shown table ? (for example, filter table) – ariana rose Commented Jan 12, 2016 at 4:28
- so you want to get the table in the data as a PDF and print it? – JGCW Commented Jan 13, 2016 at 5:07
- i already done for pdf file. but, i cannot display data only on the shown table for it page.. how is my view page? how to call the selected data to be printed? here, on print view page i just call manually from database one by one. i wanna print the only one shown in the screen @GeethW – ariana rose Commented Jan 13, 2016 at 7:54
- so you want to print a specific record? – JGCW Commented Jan 14, 2016 at 10:09
3 Answers
Reset to default 2Rather than doing the method I suggest that you use a PDF generation plugin such as pdf-laravel.
PDF-LARAVEL :
- to output to a file
$router->get('/pdf/output', function() { $html = view('pdfs.example')->render();
PDF::load($html) ->filename('/tmp/example1.pdf') ->output(); return 'PDF saved'; });
Adding the functionality to your controller
class HomeController extends Controller { private $pdf;
public function __construct(Pdf $pdf) { $this->pdf = $pdf; } public function helloWorld() { $html = view('pdfs.example1')->render(); return $this->pdf ->load($html) ->show(); }
If you want to search for other options then go to packagist and search for "pdf laravel" and you will find some packages built for Laravel 5 PDF generation.
Answer to the question 2:
I want to print data table depends on the current table show. means here is on the current page has list of all data and select option. When I select or filter table it still print all the data. The data here is collected from database
If you want to filter data and display there, you have two options, either filter data form the controller or you can use jQuery Datatables for that. Link here
All you have to do is:
Add the Js.
https://cdn.datatables/1.10.10/css/jquery.dataTables.min.css
Add the css
http://cdn.datatables/1.10.10/js/jquery.dataTables.min.js
Call your table.
$(document).ready(function(){ $('#myTable').DataTable(); });
function printData()
{
var print_ = document.getElementById("table_name");
win = window.open("");
win.document.write(print_.outerHTML);
win.print();
win.close();
}
The above function will print the data of a table which are on the current page due to the window.open("") function.
本文标签: javascriptHow to print data by current table on page in Laravel 5Stack Overflow
版权声明:本文标题:javascript - How to print data by current table on page in Laravel 5? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744206247a2595201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论