diff --git a/README.md b/README.md index dd14163..40dbd06 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,12 @@ $dt = DataTable::create($array)->build(); echo $dt; ``` +## Streaming response +Use the **stream** method to print the response +```php +DataTable::create($result)->stream(); +``` + ## Adding custom column Call the object method **addColumn** to add a custom column. This method receives the current **row** as parameter; diff --git a/src/DataTable.php b/src/DataTable.php index 996a1c2..5b05059 100644 --- a/src/DataTable.php +++ b/src/DataTable.php @@ -80,6 +80,12 @@ public static function create($result) { return new DataTable($result); } + /* Print the response with app/json header */ + public function stream() { + header("Content-type: Application/json"); + echo $this->build(); + } + public function build() { /* Building result */ diff --git a/test/test.php b/test/test.php index 7721a3e..8cae384 100644 --- a/test/test.php +++ b/test/test.php @@ -22,9 +22,6 @@ $result[] = $item; } -$dt = DataTable::create($result)->addColumn("action", function($row) { - return "Hello".$row["id"]; -})->build(); -header("Content-type: Application/json"); - -echo($dt); \ No newline at end of file +DataTable::create($result)->addColumn("action", function($row) { + return "".$row["id"].""; +})->stream(); \ No newline at end of file