Skip to content

Commit 6a71b49

Browse files
committed
introduce wrap() and nowrap() in Column
1 parent b1b86e6 commit 6a71b49

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
@@ -44,6 +44,11 @@ class Column
4444
*/
4545
public $summary = false;
4646

47+
/**
48+
* @var bool allow the content of the column to wrap into multiple lines.
49+
*/
50+
public $wrappable = true;
51+
4752
/**
4853
* @var string (optional) you can group your columns to let the user toggle the visibility of a group at once.
4954
*/
@@ -136,6 +141,20 @@ public function label($label)
136141
return $this;
137142
}
138143

144+
public function wrap()
145+
{
146+
$this->wrappable = true;
147+
148+
return $this;
149+
}
150+
151+
public function unwrap()
152+
{
153+
$this->wrappable = false;
154+
155+
return $this;
156+
}
157+
139158
public function enableSummary()
140159
{
141160
$this->summary = true;

src/Http/Livewire/LivewireDatatable.php

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

0 commit comments

Comments
 (0)