Include an external variable in hyperlink of an column
Include an external variable in hyperlink of an column
Hello again,
I'm less than beginner in DataTables or dev in general
So, I use Laravel 5.4 and several DataTables which get their data with ajax requests and everything it's working super fine.
JavaScript:
$('#tabelFurnizoriOferta').DataTable({
lengthMenu: [[15, 25, 100, -1], [15,25, 100, "All"]],
processing: true,
serverSide: true,
ajax: 'ajaxFurnizori',
columns: [
{data:'id',name:'id' , sClass: "hidden", "bSearchable": false },
{data: 'furnizor', name: 'furnizor',
"fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
$(nTd).html("<a href='introducereOferta?idFurnizor=" + oData.id + "'>" + oData.furnizor + "</a>")
}
},
{ data: 'tara', name: 'tara' },
]
});
HTML blade template:
@extends ('master')
@section('content')
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="tabelOferte" style ="width: 900px">
<table id = "tabelFurnizoriOferta" class="table table-responsive table-striped table-hover">
<thead >
<tr style="font-weight: bold" >
<td>id</td>
<td>Furnizor</td>
<td>Tara</td>
</tr>
</thead>
</table>
</div>
{{--Hidden input Get idClient from previous GET--}}
<input name="idClient" , id="IdClient" type="text" value = {{$idClient}} hidden>
</div>
</div>
</div>
@stop
PHP controller which respond to ajax request
public function furnizori(Request $request)
{
return Datatables::of(DB::table('furnizori')->
leftjoin('tari','furnizori.idTara','=','tari.id')->
get(['furnizori.id as id','furnizori.denumire as furnizor','tari.denumire as tara']))->make(true);
}
What I want, is to send the hidden input idClient in DataTables hyperlink, to concatenate somehow in the link something like "idClient" = $("#idClient)
Is this possible?
I know that one possible solution is to return view from the controller and include in it a static DataTable (with data prepared by the controller).
Replies
Someone, please help
should do it I think. i.e. just get the value and add it to the url, unless I'm misunderstanding something?
Allan