yajra/laravel-datatables 搜索不适用于 laravel 5.7

问题描述 投票:0回答:3

这是加入代码和分配

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
作为
tipo-producto
on
j
.
e
=
cod_tipo_producto
.
j
其中 (更低(
cod_tipo_producto
作为
producto
)喜欢 %1% 或更低(
e.cod_producto
作为
producto
) 喜欢 %1% 或更低(
e.nom_producto
as
producto
) 喜欢 %1% 或更低(
e.precio_venta
.
marca
)喜欢 %1% 或 更低(
nombre
.
tipo-producto
)喜欢 %1% 或更低(
nombre
作为
producto
)像 %1%))count_row_table)

    

php jquery mysql datatables laravel-5.7
3个回答
6
投票

这是样品

e.estado



0
投票


0
投票

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

2.) 确保您已在 JavaScript 文件中正确初始化 Yajra DataTable。您需要在 DataTable 初始化代码的 ajax 部分指定搜索参数。这是一个例子:`在此处输入代码`
© www.soinside.com 2019 - 2024. All rights reserved.