Skip to content

Commit 9a1fe0d

Browse files
authored
Merge pull request #421 from amvisor/wrap
introduce wrap() and nowrap() in Column
2 parents 7ca4169 + 6a71b49 commit 9a1fe0d

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class ComplexDemoTable extends LivewireDatatable
198198
|**searchable**| |Includes the column in the global search|```Column::name('name')->searchable()```|
199199
|**hideable**| |The user is able to toggle the visibility of this column|```Column::name('name')->hideable()```|
200200
|**filterable**|[*Array* $options], [*String* $filterScope]|Adds a filter to the column, according to Column type. If an array of options is passed it wil be used to populate a select input. If the column is a scope column then the name of the filter scope must also be passed|```Column::name('allegiance')->filterable(['Rebellion', 'Empire'])```|
201+
|**unwrap**| | Prevents the content of the column from being wrapped in multiple lines |```Column::name('oneliner')->unwrap()```|
201202
|**filterOn**|*String/Array* $statement|Allows you to specify a column name or sql statement upon which to perform the filter (must use SQL syntax, not Eloquent eg. ```'users.name'``` instead of ```'user.name'```). Useful if using a callback to modify the displayed values. Can pass a single string or array of strings which will be combined with ```OR```|```Column::callback(['name', 'allegiance'], function ($name, $allegiance) { return "$name is allied to $allegiance"; })->filterable(['Rebellion', 'Empire'])->filterOn('users.allegiance')```|
202203
|**view**|*String* $viewName| Passes the column value, whole row of values, and any additional parameters to a view template | _(see below)_|
203204
|**editable**| | Marks the column as editable | _(see below)_|

resources/views/livewire/datatables/datatable.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ class="px-3 py-2 text-xs font-medium tracking-wider text-green-500 uppercase bg-
156156
@foreach($this->columns as $column)
157157
@if($column['hidden'])
158158
@if($hideable === 'inline')
159-
<div class="table-cell w-5 overflow-hidden align-top"></div>
159+
<div class="table-cell w-5 @unless($column['wrappable']) whitespace-nowrap @endunless overflow-hidden align-top"></div>
160160
@endif
161161
@elseif($column['type'] === 'checkbox')
162162
@include('datatables::checkbox', ['value' => $row->checkbox_attribute])
163163
@elseif($column['type'] === 'label')
164164
@include('datatables::label')
165165
@else
166-
<div class="table-cell px-6 py-2 whitespace-no-wrap @if($column['align'] === 'right') text-right @elseif($column['align'] === 'center') text-center @else text-left @endif {{ $this->cellClasses($row, $column) }}">
166+
<div class="table-cell px-6 py-2 @unless($column['wrappable']) whitespace-nowrap @endunless @if($column['align'] === 'right') text-right @elseif($column['align'] === 'center') text-center @else text-left @endif {{ $this->cellClasses($row, $column) }}">
167167
{!! $row->{$column['name']} !!}
168168
</div>
169169
@endif

src/Column.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class Column
4545
*/
4646
public $summary = false;
4747

48+
/**
49+
* @var bool allow the content of the column to wrap into multiple lines.
50+
*/
51+
public $wrappable = true;
52+
4853
/**
4954
* @var string (optional) you can group your columns to let the user toggle the visibility of a group at once.
5055
*/
@@ -156,6 +161,20 @@ public function label($label)
156161
return $this;
157162
}
158163

164+
public function wrap()
165+
{
166+
$this->wrappable = true;
167+
168+
return $this;
169+
}
170+
171+
public function unwrap()
172+
{
173+
$this->wrappable = false;
174+
175+
return $this;
176+
}
177+
159178
public function enableSummary()
160179
{
161180
$this->summary = true;

src/Http/Livewire/LivewireDatatable.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ public function getViewColumns()
287287
'filterView',
288288
'name',
289289
'params',
290+
'wrappable',
290291
'width',
291292
'minWidth',
292293
'maxWidth',

0 commit comments

Comments
 (0)