File tree Expand file tree Collapse file tree 5 files changed +21
-4
lines changed Expand file tree Collapse file tree 5 files changed +21
-4
lines changed Original file line number Diff line number Diff line change 22All notable changes to ` omines\datatables-bundle ` will be documented in this file.
33This project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
44
5- ## [ Unreleased]
6- Nothing yet.
5+ ## [ 0.1.5] - 2018-01-25
6+ ### Fixed
7+ - Fixed inconsistency in DateTimeColumn with default/null values
78
89## [ 0.1.4] - 2018-01-21
910### Added
Original file line number Diff line number Diff line change @@ -373,6 +373,7 @@ result. If data of other types is encountered automatic conversion is attempted
373373Option | Type | Description
374374------ | ---- | -----------
375375format | string | A date format string as accepted by the [`date()`](http://php.net/manual/en/function.date.php) function. Default `'c'`.
376+ nullValue | string | Raw string to display for null values. Defaults to the empty string.
376377
377378# # TwigColumn
378379
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ class DateTimeColumn extends AbstractColumn
2727 public function normalize ($ value )
2828 {
2929 if (null === $ value ) {
30- return $ this ->getData () ;
30+ return $ this ->options [ ' nullValue ' ] ;
3131 } elseif (!$ value instanceof \DateTimeInterface) {
3232 $ value = new \DateTime ($ value );
3333 }
@@ -45,8 +45,10 @@ protected function configureOptions(OptionsResolver $resolver)
4545 $ resolver
4646 ->setDefaults ([
4747 'format ' => 'c ' ,
48+ 'nullValue ' => '' ,
4849 ])
4950 ->setAllowedTypes ('format ' , 'string ' )
51+ ->setAllowedTypes ('nullValue ' , 'string ' )
5052 ;
5153
5254 return $ this ;
Original file line number Diff line number Diff line change @@ -62,7 +62,7 @@ public function testPlainDataTable()
6262 $ sample = $ json ->data [5 ];
6363 $ this ->assertSame ('FirstName94 ' , $ sample ->firstName );
6464 $ this ->assertSame ('LastName94 ' , $ sample ->lastName );
65- $ this ->assertNull ($ sample ->employedSince );
65+ $ this ->assertEmpty ($ sample ->employedSince );
6666 $ this ->assertSame ('FirstName94 <img src="https://symfony.com/images/v5/logos/sf-positive.svg"> LastName94 ' , $ sample ->fullName );
6767 $ this ->assertRegExp ('#href="/employee/[0-9]+"# ' , $ sample ->buttons );
6868
Original file line number Diff line number Diff line change 1313namespace Tests \Unit ;
1414
1515use Omines \DataTablesBundle \Column \BoolColumn ;
16+ use Omines \DataTablesBundle \Column \DateTimeColumn ;
1617use Omines \DataTablesBundle \Column \TextColumn ;
1718use Omines \DataTablesBundle \Column \TwigColumn ;
1819use Omines \DataTablesBundle \DataTable ;
2526 */
2627class ColumnTest extends TestCase
2728{
29+ public function testDateTimeColumn ()
30+ {
31+ $ column = new DateTimeColumn ();
32+ $ column ->initialize ('test ' , 1 , [
33+ 'nullValue ' => 'foo ' ,
34+ 'format ' => 'd-m-Y ' ,
35+ ], (new DataTable ())->setName ('foo ' ));
36+
37+ $ this ->assertSame ('03-04-2015 ' , $ column ->transform ('2015-04-03 ' ));
38+ $ this ->assertSame ('foo ' , $ column ->transform (null ));
39+ }
40+
2841 public function testTextColumn ()
2942 {
3043 $ column = new TextColumn ();
You can’t perform that action at this time.
0 commit comments