这是加入代码和分配
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();
});
这里是 jQuery 代码
$(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'},
]
});
});
现在,当我尝试搜索某些内容时,它会发出错误警报这是一条错误消息
异常消息:↵↵SQLSTATE[42000]:语法错误或访问冲突: 1583 调用本机函数“LOWER”时的参数不正确(SQL: 选择计数(*)作为聚合来自(选择'1'作为
来自row_count
作为producto
内部连接e
作为marca
在d
上。e
.cod_marca
内部连接d
作为cod_marca
ontipo-producto
.j
=e
.cod_tipo_producto
其中 (更低(j
作为cod_tipo_producto
)喜欢 %1% 或更低(producto
作为e.cod_producto
) 喜欢 %1% 或更低(producto
ase.nom_producto
) 喜欢 %1% 或更低(producto
.e.precio_venta
)喜欢 %1% 或 更低(marca
.nombre
)喜欢 %1% 或更低(tipo-producto
作为nombre
)像 %1%))count_row_table)producto
这是样品
e.estado
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