Skip to content

Commit e30b720

Browse files
committed
Improve orderByNullsLast SQL generation.
Add string replace option for column and direction.
1 parent d8a965a commit e30b720

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/QueryDataTable.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,11 @@ protected function getNullsLastSql($column, $direction)
690690
{
691691
$sql = $this->config->get('datatables.nulls_last_sql', '%s %s NULLS LAST');
692692

693-
return sprintf($sql, $column, $direction);
693+
return str_replace(
694+
[':column', ':direction'],
695+
[$column, $direction],
696+
sprintf($sql, $column, $direction)
697+
);
694698
}
695699

696700
/**

src/config/datatables.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@
6464
],
6565

6666
/*
67-
* Nulls last sql pattern for Posgresql & Oracle.
68-
* For MySQL, use '-%s %s'
67+
* Nulls last sql pattern for PostgreSQL & Oracle.
68+
* For MySQL, use 'CASE WHEN :column IS NULL THEN 1 ELSE 0 END, :column :direction'
6969
*/
70-
'nulls_last_sql' => '%s %s NULLS LAST',
70+
'nulls_last_sql' => ':column :direction NULLS LAST',
7171

7272
/*
7373
* User friendly message to be displayed on user if error occurs.

0 commit comments

Comments
 (0)