Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
117
rated 0 times [  120] [ 3]  / answers: 1 / hits: 27459  / 8 Years ago, tue, june 7, 2016, 12:00:00

He is currently working on code that has to filter the data in the table. Ajax will call the link and gets the response (json) results with answer. However, I came across a problem. I have to somehow render tables and I do not want to do this by append etc.



Can I somehow again generate views or blade file?



The default view is DefController@index but ajax use url which controller is DefController@gettabledata.



public function gettabledata($id){

return response()->json(Def::find($id)->getallmy->all());

}

More From » php

 Answers
12

You can put the part in your template corresponding to the table in a separate .blade.php file, and @include that in your main layout.



main.blade.php :



<html>
...
<body>
<div class=table-container>
@include('table')
</div>
</body>
...


And



table.blade.php:



<table>
@foreach($rows as $row)
<tr>
<td> $row->title ... </td>
</tr>
@endforeach
</table>


In this way you can use a simple jQuery $('div.table-container').load(url) and on your server just render and respond that part as an html string. return view('table', $data)



Javascript:



function refreshTable() {
$('div.table-container').fadeOut();
$('div.table-container').load(url, function() {
$('div.table-container').fadeIn();
});
}

[#61861] Monday, June 6, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jameson

Total Points: 534
Total Questions: 103
Total Answers: 102

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
jameson questions
;