Skip to content

Commit

Permalink
Implemented column definition validation (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvetty authored Aug 1, 2024
1 parent 9e7bcfa commit 25ababe
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions krait/src/Tables/BaseTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,39 @@ protected function shouldRefresh(): bool
* Adds a column to the table
*
* @param string $name - The columns name
* @param string $label - The columns label
* @param ?string $label - The columns label (using the name by default)
* @param bool $hideLabel - Flags if the label should be visible in the header.
* @param bool $datetime - Flags if the column contains datetime object.
* @param bool $sortable - Flags if the column is sortable.
* @param bool $fixed - Flags if the column is resizable.
* @param string|null $classes - Additional classes that will be added on FE.
* @param callable|null $process - The column result generation callback.
* @param callable|null $sort - The column sorting callback.
*
* @throws Exception
*/
protected function column(
string $name,
string $label,
?string $label = null,
bool $hideLabel = false,
bool $datetime = false,
?string $dateformat = null,
?string $dateFormat = null,
bool $sortable = true,
bool $fixed = false,
?string $classes = null,
?callable $process = null,
?callable $sort = null,
): void {
if (! empty($this->columns[$name])) {
throw new Exception("Column $name already exists.");
}

if ($label === null) {
$label = str_replace('_', ' ', $name);
$label = str_replace('-', ' ', $label);
$label = ucfirst($label);
}

$this->columns[$name] = new TableColumnDTO(
name: $name,
label: $label,
Expand All @@ -112,7 +124,7 @@ protected function column(
classes: $classes,
process: $process,
sort: $sort,
dateFormat: $dateformat
dateFormat: $dateFormat
);
}

Expand Down

0 comments on commit 25ababe

Please sign in to comment.