@@ -28,10 +28,10 @@ class Datatables
28
28
protected $ edit_columns = array ();
29
29
protected $ sColumns = array ();
30
30
31
- public $ columns = array ();
31
+ public $ columns = array ();
32
32
public $ last_columns = array ();
33
33
34
- protected $ count_all = 0 ;
34
+ protected $ count_all = 0 ;
35
35
36
36
protected $ result_object ;
37
37
protected $ result_array = array ();
@@ -344,19 +344,48 @@ private function ordering()
344
344
345
345
if (!is_null (Input::get ('iSortCol_0 ' )))
346
346
{
347
+ $ columns = $ this ->cleanColumns ( $ this ->last_columns );
347
348
348
349
for ( $ i =0 , $ c =intval (Input::get ('iSortingCols ' )); $ i <$ c ; $ i ++ )
349
350
{
350
351
if ( Input::get ('bSortable_ ' .intval (Input::get ('iSortCol_ ' .$ i ))) == "true " )
351
352
{
352
- if (isset ($ this -> last_columns [intval (Input::get ('iSortCol_ ' .$ i ))]))
353
- $ this ->query ->orderBy ($ this -> last_columns [intval (Input::get ('iSortCol_ ' .$ i ))],Input::get ('sSortDir_ ' .$ i ));
353
+ if (isset ($ columns [intval (Input::get ('iSortCol_ ' .$ i ))]))
354
+ $ this ->query ->orderBy ($ columns [intval (Input::get ('iSortCol_ ' .$ i ))],Input::get ('sSortDir_ ' .$ i ));
354
355
}
355
356
}
356
357
357
358
}
358
359
}
359
360
361
+ private function cleanColumns ( $ cols )
362
+ {
363
+ $ _search = [
364
+ 'GROUP_CONCAT( ' ,
365
+ 'CONCAT( ' ,
366
+ 'DISTINCT( ' ,
367
+ ', ' ,
368
+ ' ) ' ,
369
+ 'as ' ,
370
+ ];
371
+
372
+ foreach ( $ cols as $ col )
373
+ {
374
+ $ _column = explode ( ' ' , str_replace ( $ _search , '' , $ col , $ count ) );
375
+
376
+ if ( $ count > 0 )
377
+ {
378
+ $ columns [] = array_shift ( $ _column );
379
+ }
380
+ else
381
+ {
382
+ $ columns [] = end ( $ _column );
383
+ }
384
+ }
385
+
386
+ return $ columns ;
387
+ }
388
+
360
389
/**
361
390
* Datatable filtering
362
391
*
@@ -365,11 +394,12 @@ private function ordering()
365
394
366
395
private function filtering ()
367
396
{
368
-
397
+ $ columns = $ this -> cleanColumns ( $ this -> columns );
369
398
370
399
if (Input::get ('sSearch ' ,'' ) != '' )
371
400
{
372
401
$ copy_this = $ this ;
402
+ $ copy_this ->columns = $ columns ;
373
403
374
404
$ this ->query ->where (function ($ query ) use ($ copy_this ) {
375
405
@@ -418,7 +448,7 @@ private function filtering()
418
448
419
449
$ db_prefix = $ this ->database_prefix ();
420
450
421
- for ($ i =0 ,$ c =count ($ this -> columns );$ i <$ c ;$ i ++)
451
+ for ($ i =0 ,$ c =count ($ columns );$ i <$ c ;$ i ++)
422
452
{
423
453
if (Input::get ('bSearchable_ ' .$ i ) == "true " && Input::get ('sSearch_ ' .$ i ) != '' )
424
454
{
@@ -429,10 +459,10 @@ private function filtering()
429
459
}
430
460
431
461
if (Config::get ('datatables.search.case_insensitive ' , false )) {
432
- $ column = $ db_prefix . $ this -> columns [$ i ];
462
+ $ column = $ db_prefix . $ columns [$ i ];
433
463
$ this ->query ->where (DB ::raw ('LOWER( ' .$ column .') ' ),'LIKE ' , $ keyword );
434
464
} else {
435
- $ this ->query ->where ($ this -> columns [$ i ], 'LIKE ' , $ keyword );
465
+ $ this ->query ->where ($ columns [$ i ], 'LIKE ' , $ keyword );
436
466
}
437
467
}
438
468
}
0 commit comments