From 96b249eb518433b0e2eabcfcfd928677c513feb4 Mon Sep 17 00:00:00 2001 From: stasbilay02 Date: Tue, 13 Aug 2024 14:30:00 +0300 Subject: [PATCH] add integer format --- examples/simple.json | 4 ++-- examples/simple.php | 13 +++++++------ src/FormatMapper.php | 2 ++ src/formats/IntegerFormat.php | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 src/formats/IntegerFormat.php diff --git a/examples/simple.json b/examples/simple.json index 5c7a148..1b64c41 100644 --- a/examples/simple.json +++ b/examples/simple.json @@ -23,8 +23,8 @@ "email" ], "data": [ - {"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas", "created_at": "17.06.2024", "status": 1}, - {"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas", "created_at": "18.06.2024", "status": 1}, + {"id": 1,"email":"fas1@mail.ru","description":"sdgsdfg","description2":"ffdghdas", "created_at": "17.06.2024", "status": "1"}, + {"id": 2,"email":"fas2@mail.ru","description":"fafdgdfgsdfdfs","description2":"ffdghdas", "created_at": "18.06.2024", "status": "1"}, {"id": 3,"email":"fas3@mail.ru","description":"fafdgdssdfgdfs","description2":"ffdghdas", "created_at": "19.06.2024", "status": 2}, {"id": 4,"email":"fas4@mail.ru","description":"fafd dsfgsd vcbgdfs","description2":"ffdghdas", "created_at": "20.06.2024", "status": 1}, {"id": 5,"email":"fas5@mail.ru","description":"fafdgghjgfdfs","description2":"ffdghdas", "created_at": "21.06.2024", "status": 1}, diff --git a/examples/simple.php b/examples/simple.php index b96b64d..2527697 100644 --- a/examples/simple.php +++ b/examples/simple.php @@ -7,22 +7,23 @@ use Itguild\Tables\ListJsonTable; $json = file_get_contents('simple.json'); $table = new ListJsonTable($json); -//$table->columns([ $table->columns([ "created_at" => [ - "format" => "date:Y-m-d", + "format" => "date:Y-m-d" ], 'description' => [ "format" => "html", "style" => ["width" => "300px"], - "filter" => '', + "filter" => function () {}, "value" => function ($cell) { return "$cell"; } ], - 'status' => function ($cell) { - return getStatusLabel()[$cell]; - }, + 'status' => [ + "format" => "integer", + "value" => function ($cell) { + return getStatusLabel()[$cell]; +}], 'email' => function ($cell) { return "$cell"; }, diff --git a/src/FormatMapper.php b/src/FormatMapper.php index 7ade4d2..78f52e5 100644 --- a/src/FormatMapper.php +++ b/src/FormatMapper.php @@ -4,6 +4,7 @@ namespace Itguild\Tables; use Itguild\Tables\formats\DateFormat; use Itguild\Tables\formats\HtmlFormat; +use Itguild\Tables\formats\IntegerFormat; use Itguild\Tables\formats\PhoneNumberFormat; use Itguild\Tables\formats\TextFormat; @@ -17,6 +18,7 @@ class FormatMapper 'date' => DateFormat::class, 'html' => HtmlFormat::class, 'phoneNumber' => PhoneNumberFormat::class, + 'integer' => IntegerFormat::class, ]; } diff --git a/src/formats/IntegerFormat.php b/src/formats/IntegerFormat.php new file mode 100644 index 0000000..31bf8b4 --- /dev/null +++ b/src/formats/IntegerFormat.php @@ -0,0 +1,14 @@ +