Skip to content

Commit 0e7db3f

Browse files
authored
Merge pull request #262 from yajra/default-content
feat: column default content
2 parents c670194 + b9f1df4 commit 0e7db3f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Html/Column.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,20 @@ public function exportFormat(string|callable $format): static
595595
return $this;
596596
}
597597

598+
/**
599+
* Set column default content.
600+
*
601+
* @return $this
602+
*
603+
* @see https://datatables.net/reference/option/columns.defaultContent
604+
*/
605+
public function defaultContent(string $content): static
606+
{
607+
$this->attributes['defaultContent'] = $content;
608+
609+
return $this;
610+
}
611+
598612
public function toArray(): array
599613
{
600614
if (! $this->isAuthorized()) {

tests/Html/Builder/BuilderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,21 @@ public function it_can_set_template_data(): void
328328
$builder->generateScripts()->toHtml()
329329
);
330330
}
331+
332+
#[Test]
333+
public function it_can_set_column_default_content(): void
334+
{
335+
$builder = $this->getHtmlBuilder();
336+
337+
$builder->columns([
338+
Column::make('name'),
339+
Column::make('email')->defaultContent('N/A'),
340+
Column::make('age')->defaultContent('<button>&lt;18</button>'),
341+
]);
342+
343+
$this->assertCount(3, $builder->getColumns());
344+
$this->assertNull($builder->getColumns()[0]->defaultContent);
345+
$this->assertEquals('N/A', $builder->getColumns()[1]->defaultContent);
346+
$this->assertEquals('<button>&lt;18</button>', $builder->getColumns()[2]->defaultContent);
347+
}
331348
}

0 commit comments

Comments
 (0)