44
55namespace CakeDC \Datatables \Datatable ;
66
7+ use CakeDC \Datatables \Datatables ;
8+ use CakeDC \Datatables \Exception \MissConfiguredException ;
9+ use CakeDC \Datatables \View \LinkFormatter \LinkInterface ;
710use Cake \Core \InstanceConfigTrait ;
811use Cake \Utility \Inflector ;
912use Cake \Utility \Text ;
10- use CakeDC \Datatables \Datatables ;
11- use CakeDC \Datatables \Exception \MissConfiguredException ;
1213use Exception ;
1314use InvalidArgumentException ;
1415
@@ -181,20 +182,33 @@ class Datatable
181182 $('#:tagId').find('#from'+colIdx)
182183 .datepicker()
183184 .on('change', function () {
184- if($('#to'+colIdx).val() !== '') {
185+ if($('#to'+colIdx).val() !== '' && validateDate($('#to'+colIdx).val()) ) {
185186 api.column(colIdx).search($('#:tagId').find('#from'+colIdx).val() + '|' + $('#:tagId').find('#to' + colIdx).val()).draw();
186187 } else {
187- api.column(colIdx).search($('#:tagId').find('#from'+colIdx).val() + '|').draw();
188+ $('#to'+colIdx).val('');
189+ if($('#from'+colIdx).val() !== '' && validateDate($('#from'+colIdx).val())) {
190+ api.column(colIdx).search($('#:tagId').find('#from'+colIdx).val() + '|').draw();
191+ } else {
192+ $('#from'+colIdx).val('');
193+ api.column(colIdx).search('').draw();
194+ }
188195 }
189196 });
190197 $('#:tagId').find('#to'+colIdx)
191198 .datepicker()
192199 .on('change', function () {
193- if($('#from'+colIdx).val() !== '') {
200+ if($('#from'+colIdx).val() !== '' && validateDate($('#from'+colIdx).val()) ) {
194201 api.column(colIdx).search($('#:tagId').find('#from'+colIdx).val() + '|' + $('#:tagId').find('#to' + colIdx).val()).draw();
195202 } else {
196- api.column(colIdx).search( '|' + $('#:tagId').find('#to' + colIdx).val()).draw();
203+ $('#from'+colIdx).val('');
204+ if ($('#to'+colIdx).val() !== '' && validateDate($('#to'+colIdx).val())) {
205+ api.column(colIdx).search('|' + $('#:tagId').find('#to' + colIdx).val()).draw();
206+ } else {
207+ $('#to'+colIdx).val('');
208+ api.column(colIdx).search('').draw();
209+ }
197210 }
211+
198212 });
199213 break;
200214 case 'input':
@@ -488,6 +502,11 @@ public function getDatatableScript(): string
488502 );
489503 }
490504
505+ public function setCallback ($ callback ): void
506+ {
507+ $ this ->setConfig ('drawCallback ' , $ callback );
508+ }
509+
491510 public function getCommonScript (): string
492511 {
493512 return 'console.log("from getCommonScript") ' ;
@@ -518,7 +537,7 @@ public function setGetDataUrl($defaultUrl = null)
518537 };
519538 GET_DATA ;
520539 } else {
521- if ($ csrfToken !== null ){
540+ if ($ csrfToken !== null ) {
522541 $ headers = "headers: { 'X-CSRF-Token': ' {$ csrfToken }' }, " ;
523542 } else {
524543 $ headers = "" ;
@@ -582,9 +601,9 @@ protected function processColumnRenderCallbacks()
582601 if ($ key ['width ' ] ?? null ) {
583602 $ output .= "\nwidth: ' {$ key ['width ' ]}', " ;
584603 }
585- if ($ key ['className ' ] ?? null ) {
586- $ output .= "\nclassName: ' {$ key ['className ' ]}', " ;
587- }
604+ if ($ key ['className ' ] ?? null ) {
605+ $ output .= "\nclassName: ' {$ key ['className ' ]}', " ;
606+ }
588607 }
589608 $ output .= '} ' ;
590609
@@ -606,7 +625,7 @@ protected function processActionLinkList(array $sourceLinks): array
606625 {
607626 $ links = [];
608627 foreach ($ sourceLinks as $ link ) {
609- $ links [] = $ this ->processActionLink ($ link );
628+ $ links [] = $ this ->processActionLink ($ link )-> render () ;
610629 }
611630
612631 return $ links ;
@@ -616,34 +635,29 @@ protected function processActionLinkList(array $sourceLinks): array
616635 * Format link with specified options from links array.
617636 *
618637 * @param array $link
619- * @return string
638+ * @return LinkInterface
620639 */
621- protected function processActionLink (array $ link ): string
640+ protected function processActionLink (array $ link ): LinkInterface
622641 {
623642 switch ($ link ['type ' ] ?? null ) {
624643 case Datatables::LINK_TYPE_DELETE :
625644 case Datatables::LINK_TYPE_PUT :
626645 case Datatables::LINK_TYPE_POST :
627- $ output = new \CakeDC \Datatables \View \Formatter \ Link \PostLink ($ this ->Helper , $ link );
646+ $ output = new \CakeDC \Datatables \View \LinkFormatter \PostLink ($ this ->Helper , $ link );
628647 break ;
629648 case Datatables::LINK_TYPE_CUSTOM :
630- if (!class_exists ($ link ['formatter ' ] ?? null )) {
631- throw new \OutOfBoundsException ("Please specify a custom formatter " );
649+ if (!class_exists ($ link ['linkFormatter ' ] ?? null )) {
650+ throw new \OutOfBoundsException ("Please specify a custom linkFormatter " );
632651 }
633- $ output = new $ link ['formatter ' ]($ this ->Helper , $ link );
634-
635- if (!method_exists ($ output , 'link ' )) {
636- throw new \OutOfBoundsException ("Method link is not found in class " );
637- }
638-
652+ $ output = new $ link ['linkFormatter ' ]($ this ->Helper , $ link );
639653 break ;
640654 case Datatables::LINK_TYPE_GET :
641655 default :
642- $ output = new \CakeDC \Datatables \View \Formatter \ Link \Link ($ this ->Helper , $ link );
656+ $ output = new \CakeDC \Datatables \View \LinkFormatter \Link ($ this ->Helper , $ link );
643657 break ;
644658 }
645659
646- return $ output-> link () ;
660+ return $ output ;
647661 }
648662
649663 /**
0 commit comments