Skip to content

Commit

Permalink
added stream feature
Browse files Browse the repository at this point in the history
  • Loading branch information
emagombe committed Aug 16, 2020
1 parent be13e02 commit 6d67114
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions src/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
9 changes: 3 additions & 6 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
DataTable::create($result)->addColumn("action", function($row) {
return "<b>".$row["id"]."</b>";
})->stream();

0 comments on commit 6d67114

Please sign in to comment.