Reputation: 154
Here is join code and assign Datatables
Route::get('Productos',function(){
$query = DB::table('producto as e')
->select('e.cod_producto', 'e.nom_producto', 'e.precio_venta', 'd.nombre as nombre_marca', 'j.nombre as nombre_tipo', DB::raw('if(e.estado = 0,\'Activo\',\'Eliminado\') as estado'))
->join('marca as d','e.cod_marca', '=', 'd.cod_marca')
->join('tipo-producto as j', 'e.cod_tipo_producto', '=', 'j.cod_tipo_producto');
return datatables()
->of($query)
->addColumn('btn','actions')
->rawColumns(['btn'])
->toJson();
});
Here is jQuery code
$(document).ready(function(){
$('#Productos').DataTable({
"bAutoWidth": false,
"destroy": true,
"responsive": true,
"serverSide":true,
"ajax":'{{url('api/Productos')}}',
"columnDefs": [ {
"targets": 'no-sort',
"orderable": false,
"searchable": false,
}],
"columns":[
{data: 'cod_producto'},
{data: 'nom_producto'},
{data: 'precio_venta'},
{data: 'nombre_marca'},
{data: 'nombre_tipo'},
{data: 'estado'},
{data: 'btn'},
]
});
});
Now when i try to search something it is giving me alert with error Here is an error message
Exception Message:↵↵SQLSTATE[42000]: Syntax error or access violation: 1583 Incorrect parameters in the call to native function 'LOWER' (SQL: select count(*) as aggregate from (select '1' as
row_count
fromproducto
ase
inner joinmarca
asd
one
.cod_marca
=d
.cod_marca
inner jointipo-producto
asj
one
.cod_tipo_producto
=j
.cod_tipo_producto
where (LOWER(producto
ase.cod_producto
) LIKE %1% or LOWER(producto
ase.nom_producto
) LIKE %1% or LOWER(producto
ase.precio_venta
) LIKE %1% or LOWER(marca
.nombre
) LIKE %1% or LOWER(tipo-producto
.nombre
) LIKE %1% or LOWER(producto
ase.estado
) LIKE %1%)) count_row_table)
Upvotes: 0
Views: 9313
Reputation: 1
hai i have a same problem, this my datatable :
public function yajra(Request $request)
{
DB::statement(DB::raw('set @rownum=0'));
$pengeluaran = DB::table('pengeluaran as a')->join('jenis_pengeluaran as b','a.jenis_pengeluaran', '=','b.id')->select([
DB::raw('@rownum := @rownum + 1 AS rownum'),
'a.id',
'a.tanggal',
'a.no_nota',
'a.uraian',
'a.jumlah',
'a.jenis_pengeluaran',
'b.nama']);
$datatables = Datatables::of($pengeluaran)->addColumn('action', function ($pl) {
$url_edit = url('pengeluaran/'.$pl->id);
$url_hapus = url('pengeluaran/'.$pl->id);
return '<a href="'.$url_edit.'" class="btn btn-outline-secondary"> <i class="ni ni-ruler-pencil"></i>Edit</a> <a href="'.$url_hapus.'" class="btn btn-outline-secondary btn-hapus" style="color:red;"> <i class="ni ni-fat-remove" style="color:red;"></i>Hapus</a>';
})->editColumn('jumlah', function($pl){
$jumlah = $pl->jumlah;
$jumlah = number_format($jumlah,0);
$jumlah = str_replace(',', '.', $jumlah);
return $jumlah;
})->editColumn('tanggal', function($pl){
$tanggal = $pl->tanggal;
$tanggal = date('d M Y', strtotime($tanggal));
return $tanggal;
});
if ($keyword = $request->get('search')['value']) {
$datatables->filterColumn('rownum', 'whereRaw', '@rownum + 1 like ?', ["%{$keyword}%"]);
}
return $datatables->make(true);
}
and this is my javascript
<script type="text/javascript">
$(document).ready(function(){
$('#peng').DataTable({
processing: true,
serverSide: true,
ajax: "{{ url('pengeluaran/yajra')}}",
columns: [
// or just disable search since it's not really searchable. just add searchable:false
{data: 'rownum', name: 'rownum'},
{data: 'tanggal', name: 'tanggal'},
{data: 'no_nota', name: 'no_nota'},
{data: 'uraian', name: 'uraian'},
{data: 'jumlah', name: 'jumlah'},
{data: 'nama', name: 'nama'},
{data: 'action', name: 'action', orderable: false, searchable: false}
]
});
i'm using "yajra/laravel-datatables-oracle": "~9.0" and laravel 7
Upvotes: 0
Reputation: 1932
Set your Datatable columns name base on your join data field from your query
Here is the sample
"columns":[
{data: 'cod_producto', name:'e.code_product'},
{data: 'nom_producto', name:'e.nom_producto'},
....
Upvotes: 7