@@ -475,11 +475,15 @@ public function renderPaginator($current_page, $total, BasePage $controller, $pa
475475 */
476476 public function renderAdminTable ($ elements , $ header = null , BasePage $ current_page = null )
477477 {
478+ $ table_id = 'listing-table ' ;
479+
480+
478481 $ table = $ this ->getContainer ()->make (
479482 TagElement::class,
480483 ['options ' => [
481484 'tag ' => 'table ' ,
482485 'width ' => '100% ' ,
486+ 'id ' => $ table_id ,
483487 'cellspacing ' => '0 ' ,
484488 'cellpadding ' => '0 ' ,
485489 'border ' => '0 ' ,
@@ -518,6 +522,42 @@ public function renderAdminTable($elements, $header = null, BasePage $current_pa
518522 $ header = array_flip ($ header );
519523 }
520524
525+ $ add_searchrow = false ;
526+ if ($ current_page instanceof BasePage) {
527+ $ search_row = $ this ->getContainer ()->make (
528+ TagElement::class,
529+ ['options ' => [
530+ 'tag ' => 'tr ' ,
531+ ]]
532+ );
533+ $ style ="max-width:80%;font-size: 9px;line-height: 11px;max-width: 100%;padding: 3px 1px;margin: 0;border: 1px solid #555;border-radius: 2px; " ;
534+ foreach ($ header as $ k => $ v ) {
535+ if (is_array ($ v ) && isset ($ v ['search ' ]) && boolval ($ v ['search ' ]) == true ) {
536+ $ td = $ this ->getContainer ()->make (
537+ TagElement::class,
538+ ['options ' => [
539+ 'tag ' => 'td ' ,
540+ 'text ' => '<input style=" ' .$ style .'" name="search[ ' .$ v ['search ' ].']" value=" ' .$ current_page ->getRequest ()->query ->get ('search ' )[$ v ['search ' ]].'"/> ' ,
541+ ]]
542+ );
543+ $ add_searchrow = true ;
544+ } else {
545+ $ td = $ this ->getContainer ()->make (
546+ TagElement::class,
547+ ['options ' => [
548+ 'tag ' => 'td ' ,
549+ 'text ' => ' ' ,
550+ ]]
551+ );
552+ }
553+
554+ $ search_row ->addChild ($ td );
555+ }
556+ if ($ add_searchrow ) {
557+ $ tbody ->addChild ($ search_row );
558+ }
559+ }
560+
521561 // tbody
522562 foreach ($ elements as $ key => $ elem ) {
523563 // ensure all header cols are in row cols
@@ -571,19 +611,29 @@ public function renderAdminTable($elements, $header = null, BasePage $current_pa
571611 ]]
572612 );
573613
574- foreach ($ header as $ th => $ column_name ) {
614+ foreach ($ header as $ th => $ column ) {
575615 $ th = $ this ->getUtils ()->translate ($ th , $ current_page ->getCurrentLocale ());
576616 $ request_params = [];
577617 if ($ current_page instanceof BasePage) {
578618 $ request_params = $ current_page ->getRequest ()->query ->all ();
579619
580- if (!empty ($ column_name )) {
581- $ val = 'DESC ' ;
582- if (isset ($ request_params ['order ' ][$ column_name ])) {
583- $ val = ($ request_params ['order ' ][$ column_name ] == 'ASC ' ) ? 'DESC ' : 'ASC ' ;
620+ if (!empty ($ column )) {
621+ $ orderby = null ;
622+ if (is_array ($ column )) {
623+ if (isset ($ column ['order ' ])) {
624+ $ orderby = $ column ['order ' ];
625+ }
626+ } else {
627+ $ orderby = $ column ;
628+ }
629+ if (!empty ($ orderby )) {
630+ $ val = 'DESC ' ;
631+ if (isset ($ request_params ['order ' ][$ orderby ])) {
632+ $ val = ($ request_params ['order ' ][$ orderby ] == 'ASC ' ) ? 'DESC ' : 'ASC ' ;
633+ }
634+ $ request_params ['order ' ][$ orderby ] = $ val ;
635+ $ th = '<a class="ordering" href=" ' .($ current_page ->getControllerUrl ().'? ' .http_build_query ($ request_params )).'"> ' .$ th .$ this ->getUtils ()->getIcon ($ val == 'DESC ' ? 'arrow-down ' : 'arrow-up ' ).'</a> ' ;
584636 }
585- $ request_params ['order ' ][$ column_name ] = $ val ;
586- $ th = '<a class="ordering" href=" ' .($ current_page ->getControllerUrl ().'? ' .http_build_query ($ request_params )).'"> ' .$ th .$ this ->getUtils ()->getIcon ($ val == 'DESC ' ? 'arrow-down ' : 'arrow-up ' ).'</a> ' ;
587637 }
588638 }
589639
@@ -604,6 +654,22 @@ public function renderAdminTable($elements, $header = null, BasePage $current_pa
604654 }
605655 $ thead ->addChild ($ row );
606656
657+ if (($ current_page instanceof BasePage)) {
658+ $ request_params = $ current_page ->getRequest ()->query ->all ();
659+ if (isset ($ request_params ['order ' ]) || isset ($ request_params ['search ' ])) {
660+ $ current_page ->addActionLink ('reset-btn ' , 'reset-btn ' , $ this ->getUtils ()->translate ('Reset ' , $ current_page ->getCurrentLocale ()), $ current_page ->getControllerUrl (), 'btn btn-sm btn-warning ' );
661+ }
662+ if ($ add_searchrow ) {
663+ $ query_params = '' ;
664+ if (!empty ($ request_params )) {
665+ $ query_params = (array ) $ request_params ;
666+ unset($ query_params ['search ' ]);
667+ $ query_params = http_build_query ($ query_params );
668+ }
669+ $ current_page ->addActionLink ('search-btn ' , 'search-btn ' , $ this ->getUtils ()->getIcon ('zoom-in ' ).$ this ->getUtils ()->translate ('Search ' , $ current_page ->getCurrentLocale ()), $ current_page ->getControllerUrl () . (!empty ($ query_params ) ? '? ' :'' ) . $ query_params , 'btn btn-sm btn-primary ' , ['data-target ' => '# ' .$ table_id ]);
670+ }
671+ }
672+
607673 return $ table ;
608674 }
609675
0 commit comments