@@ -31,6 +31,7 @@ class LivewireDatatable extends Component
3131 public $ sort ;
3232 public $ direction ;
3333 public $ activeDateFilters = [];
34+ public $ activeDatetimeFilters = [];
3435 public $ activeTimeFilters = [];
3536 public $ activeSelectFilters = [];
3637 public $ activeBooleanFilters = [];
@@ -170,6 +171,7 @@ public function applyToTable($options)
170171 'search ' ,
171172 'activeSelectFilters ' ,
172173 'activeDateFilters ' ,
174+ 'activeDatetimeFilters ' ,
173175 'activeTimeFilters ' ,
174176 'activeBooleanFilters ' ,
175177 'activeTextFilters ' ,
@@ -197,6 +199,7 @@ public function resetTable()
197199 $ this ->setPage (1 );
198200 $ this ->activeSelectFilters = [];
199201 $ this ->activeDateFilters = [];
202+ $ this ->activeDatetimeFilters = [];
200203 $ this ->activeTimeFilters = [];
201204 $ this ->activeTextFilters = [];
202205 $ this ->activeBooleanFilters = [];
@@ -531,6 +534,7 @@ public function setSessionStoredFilters()
531534 'boolean ' => $ this ->activeBooleanFilters ,
532535 'select ' => $ this ->activeSelectFilters ,
533536 'date ' => $ this ->activeDateFilters ,
537+ 'datetime ' => $ this ->activeDatetimeFilters ,
534538 'time ' => $ this ->activeTimeFilters ,
535539 'number ' => $ this ->activeNumberFilters ,
536540 'search ' => $ this ->search ,
@@ -638,6 +642,10 @@ public function initialiseDefaultFilters()
638642 $ this ->activeDateFilters [$ columnIndex ] = $ value ;
639643 }
640644
645+ if ($ column ['type ' ] === 'datetime ' ) {
646+ $ this ->activeDatetimeFilters [$ columnIndex ] = $ value ;
647+ }
648+
641649 if ($ column ['type ' ] === 'time ' ) {
642650 $ this ->activeTimeFilters [$ columnIndex ] = $ value ;
643651 }
@@ -672,6 +680,10 @@ public function initialiseFilters()
672680 $ this ->activeDateFilters = $ filters ['date ' ];
673681 }
674682
683+ if (! empty ($ filters ['datetime ' ])) {
684+ $ this ->activeDatetimeFilters = $ filters ['datetime ' ];
685+ }
686+
675687 if (! empty ($ filters ['time ' ])) {
676688 $ this ->activeTimeFilters = $ filters ['time ' ];
677689 }
@@ -923,6 +935,22 @@ public function doDateFilterEnd($index, $end)
923935 $ this ->setSessionStoredFilters ();
924936 }
925937
938+ public function doDatetimeFilterStart ($ index , $ start )
939+ {
940+ $ this ->activeDatetimeFilters [$ index ]['start ' ] = $ start ;
941+ $ this ->setVisibleSelected ();
942+ $ this ->setPage (1 );
943+ $ this ->setSessionStoredFilters ();
944+ }
945+
946+ public function doDatetimeFilterEnd ($ index , $ end )
947+ {
948+ $ this ->activeDatetimeFilters [$ index ]['end ' ] = $ end ;
949+ $ this ->setVisibleSelected ();
950+ $ this ->setPage (1 );
951+ $ this ->setSessionStoredFilters ();
952+ }
953+
926954 public function doTimeFilterStart ($ index , $ start )
927955 {
928956 $ this ->activeTimeFilters [$ index ]['start ' ] = $ start ;
@@ -980,6 +1008,7 @@ public function removeSelectFilter($column, $key = null)
9801008 public function clearAllFilters ()
9811009 {
9821010 $ this ->activeDateFilters = [];
1011+ $ this ->activeDatetimeFilters = [];
9831012 $ this ->activeTimeFilters = [];
9841013 $ this ->activeSelectFilters = [];
9851014 $ this ->activeBooleanFilters = [];
@@ -1154,6 +1183,7 @@ public function getNumberFiltersProperty()
11541183 public function getActiveFiltersProperty ()
11551184 {
11561185 return count ($ this ->activeDateFilters )
1186+ || count ($ this ->activeDatetimeFilters )
11571187 || count ($ this ->activeTimeFilters )
11581188 || count ($ this ->activeSelectFilters )
11591189 || count ($ this ->activeBooleanFilters )
@@ -1209,6 +1239,7 @@ public function buildDatabaseQuery($export = false)
12091239 ->addTextFilters ()
12101240 ->addNumberFilters ()
12111241 ->addDateRangeFilter ()
1242+ ->addDatetimeRangeFilter ()
12121243 ->addTimeRangeFilter ()
12131244 ->addComplexQuery ()
12141245 ->addSort ();
@@ -1504,6 +1535,27 @@ public function addDateRangeFilter()
15041535 return $ this ;
15051536 }
15061537
1538+ public function addDatetimeRangeFilter ()
1539+ {
1540+ if (! count ($ this ->activeDatetimeFilters )) {
1541+ return $ this ;
1542+ }
1543+
1544+ $ this ->query ->where (function ($ query ) {
1545+ foreach ($ this ->activeDatetimeFilters as $ index => $ filter ) {
1546+ if (! ((isset ($ filter ['start ' ]) && $ filter ['start ' ] != '' ) || (isset ($ filter ['end ' ]) && $ filter ['end ' ] != '' ))) {
1547+ break ;
1548+ }
1549+ $ query ->whereBetween ($ this ->getColumnFilterStatement ($ index )[0 ], [
1550+ isset ($ filter ['start ' ]) && $ filter ['start ' ] != '' ? $ filter ['start ' ] : config ('livewire-datatables.default_time_start ' , '0000-00-00 00:00 ' ),
1551+ isset ($ filter ['end ' ]) && $ filter ['end ' ] != '' ? $ filter ['end ' ] : config ('livewire-datatables.default_time_end ' , '9999-12-31 23:59 ' ),
1552+ ]);
1553+ }
1554+ });
1555+
1556+ return $ this ;
1557+ }
1558+
15071559 public function addTimeRangeFilter ()
15081560 {
15091561 if (! count ($ this ->activeTimeFilters )) {
0 commit comments