Hi Everyone,
I use "yajra/laravel-datatables-oracle": "^6.3"
and laravel 5.2.
Everyting ok with listing datatables but when I start searching I get the error
SQLSTATE[42000]: Syntax error or access violation: 1583 Incorrect parameters in the call to native function 'LOWER' ...
public function index(Request $request){
$items = DB::table('items as it')->select('it.*','c.name as category')
->join('category as c', 'it.category_id', '=', 'c.id');
$datatables = Datatables::of($items)
->addColumn('no', function ($items) { return ''; }));
if ($keyword = $request->get('search')['value']) {
$datatables->filterColumn('name', 'whereRaw', "items.name like ? ", ["%$keyword%"]);
$datatables->filterColumn('category', 'whereRaw', "category.name like ? ", ["%$keyword%"]);
}
return $datatables->make(true);
}
$('#items_table').DataTable({
processing: true,
serverSide: true,
iDisplayLength: 25,
'responsive': true,
'language' : {
"sSearchPlaceholder": "Search..",
"lengthMenu": "_MENU_",
"search": "_INPUT_",
"paginate": {
"previous" : '<i class="icon md-chevron-left"></i>',
"next" : '<i class="icon md-chevron-right"></i>'
}
},
order: [[ 1, "asc" ]],
ajax: {
url : 'items/index',
type : "POST",
data : function (d) {}
},
columns: [
{ data: 'no', orderable: false, bSearchable: false },
{ data: 'name', name: 'name' },
{ data: 'category', name: 'category' },
],
"fnRowCallback" : function(nRow, aData, iDisplayIndex){
// For auto numbering at 'No' column
var start = tbl.page.info().start;
$('td:eq(0)',nRow).html(start + iDisplayIndex + 1);
},
});
Please Help Me.
Thanks!
@seven9 have you tried updating to the latest stable version v6.22.5
?
Hi @yajra ,
I already updated and tried it.That problem is happen when I use table alias like
DB::table('items as it')
and join many talbes with laravel query builder.
Thanks..
@seven9 , I just got the same issue, but resolved it eventually. The fix was in my JS.
I made sure the column properties match the alias and the actual columns.
Using your example:
data: 'name', name: 'name'
data: 'category', name: 'category'
data-value : _alias_
name-value : _actual column_
try:
data: 'name', name: 'it.name'
data: 'category', name: 'c.name'
Thanks @jedknyt and nice fix.
@jedknyt you've saved me a lot of time bro
@jedknyt thanks for sharing the solution. 👍
Query
$sales = \DB::table('driver_ride_transactions as drt')
->join('bookings', 'bookings.id', '=', 'drt.booking_id')
->join('businesses', 'businesses.id', '=', 'bookings.business_id')
->leftJoin('users as driver_u', 'drt.user_id', '=', 'driver_u.id')
->leftJoin('users as app_u', 'bookings.user_id', '=', 'app_u.id')
->select('drt.id', 'drt.status', 'driver_u.first_name as driver_name', 'app_u.first_name as app_user_name', 'businesses.name as destination', 'drt.created_at');
Javascript Code
$('#sales-table').DataTable({
processing: true,
serverSide: true,
order: [ [4, 'desc'] ],
ajax: '{{ route('admin:fetch:ride:transactions') }}',
columns: [
{data: 'id', name: 'drt.id'},
{data: 'destination', name: 'destination'},
{data: 'driver_name', name: 'driver_name'},
{data: 'app_user_name', name: 'app_user_name'},
{data: 'created_at', name: 'drt.created_at'},
{data: 'status', name: 'drt.status'}
]
});
Everything works perfectly, but Still getting this error while searching _Search Error Incorrect parameters in the call to native function 'LOWER'_
What am I missing? @yajra @jedknyt ?
@siddharthghedia since you are using join, I think you should include the table name too on each columns and avoid using the alias on name
values. Use the actual column value.
columns: [
{data: 'id', name: 'drt.id'},
{data: 'destination', name: 'drt.destination'},
{data: 'driver_name', name: 'driver_u.first_name'},
{data: 'app_user_name', name: 'app_u.first_name'},
{data: 'created_at', name: 'drt.created_at'},
{data: 'status', name: 'drt.status'}
]
@yajra Thank you so much for replying, I tried the same code which you wrote, but still gave me the same error and you asked not use alias on name
right? But here driver_u
and app_u
are the aliases already. How could I solve it? Thank you in advance.
Hello @siddharthghedia , i have the same issue, do you have any solution.
Thank you in advance.
Me sirvió de mucho, resolví el problema... gracias por compartir la solución
@siddharthghedia since you are using join, I think you should include the table name too on each columns and avoid using the alias on
name
values. Use the actual column value.columns: [ {data: 'id', name: 'drt.id'}, {data: 'destination', name: 'drt.destination'}, {data: 'driver_name', name: 'driver_u.first_name'}, {data: 'app_user_name', name: 'app_u.first_name'}, {data: 'created_at', name: 'drt.created_at'}, {data: 'status', name: 'drt.status'} ]
IT works for me. Thank you so much
@siddharthghedia since you are using join, I think you should include the table name too on each columns and avoid using the alias on
name
values. Use the actual column value.columns: [ {data: 'id', name: 'drt.id'}, {data: 'destination', name: 'drt.destination'}, {data: 'driver_name', name: 'driver_u.first_name'}, {data: 'app_user_name', name: 'app_u.first_name'}, {data: 'created_at', name: 'drt.created_at'}, {data: 'status', name: 'drt.status'} ]
It works for me. Thanks you so much
Most helpful comment
@seven9 , I just got the same issue, but resolved it eventually. The fix was in my JS.
I made sure the column properties match the alias and the actual columns.
Using your example:
data: 'name', name: 'name'
data: 'category', name: 'category'
data-value : _alias_
name-value : _actual column_
try:
data: 'name', name: 'it.name'
data: 'category', name: 'c.name'