File tree Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Expand file tree Collapse file tree 3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 2727
2828$ grid ->setModel ($ model );
2929
30+ // add country flag column
31+ $ grid ->addColumn ('flag ' , [
32+ Table \Column \CountryFlag::class,
33+ 'codeField ' => $ model ->fieldName ()->iso ,
34+ 'nameField ' => $ model ->fieldName ()->name ,
35+ ]);
36+
3037// Adding Quicksearch on Name field using auto query.
3138$ grid ->addQuickSearch ([$ model ->fieldName ()->name ], true );
3239
Original file line number Diff line number Diff line change @@ -482,7 +482,7 @@ public function renderRow(): void
482482 if (!is_array ($ columns )) {
483483 $ columns = [$ columns ];
484484 }
485- $ field = ! is_int ($ name ) && $ this -> model -> hasField ( $ name ) ? $ this ->model ->getField ($ name ) : null ;
485+ $ field = is_int ($ name ) ? null : $ this ->model ->getField ($ name );
486486 foreach ($ columns as $ column ) {
487487 $ html_tags = array_merge ($ column ->getHtmlTags ($ this ->model , $ field ), $ html_tags );
488488 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Atk4 \Ui \Table \Column ;
6+
7+ use Atk4 \Data \Field ;
8+ use Atk4 \Data \Model ;
9+ use Atk4 \Ui \Table ;
10+
11+ class CountryFlag extends Table \Column
12+ {
13+ /** Name of country code model field (in ISO 3166-1 alpha-2 format) */
14+ public string $ codeField ;
15+
16+ /** Optional name of model field which contains full country name. */
17+ public ?string $ nameField = null ;
18+
19+ public function getHtmlTags (Model $ row , ?Field $ field ): array
20+ {
21+ $ countryCode = $ row ->get ($ this ->codeField );
22+ $ countryName = $ this ->nameField ? $ row ->get ($ this ->nameField ) : null ;
23+
24+ return [
25+ $ field ->shortName => $ countryCode === null
26+ ? ''
27+ : $ this ->getApp ()->getTag ('i ' , [
28+ 'class ' => strtolower ($ countryCode ) . ' flag ' ,
29+ 'title ' => strtoupper ($ countryCode ) . ($ countryName === null ? '' : ' - ' . $ countryName ),
30+ ]),
31+ ];
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments