Skip to content

Commit

Permalink
1.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur LORENT committed May 14, 2019
1 parent d23067e commit 96ed523
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [1.0.13](https://github.com/Okipa/laravel-table/releases/tag/1.0.13)

2019-05-14

- Fixed a use case when no sortable columns are defined and an empty `orderBy` is called in the SQL request, causing an exception with MySQL.

## [1.0.12](https://github.com/Okipa/laravel-table/releases/tag/1.0.12)

2019-05-09
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public function index(Request $request) {
// this example assume that a bootstrap modal component has been included in your view
// https://getbootstrap.com/docs/4.3/components/modal/#modal-components
const destroyButton = $('form.destroy button[type="submit"]');
destroyButton.click(function(e) {
destroyButton.click((e) => {
e.preventDefault();
const $this = $(e.target);
const message = $this.data("confirm");
Expand Down
4 changes: 3 additions & 1 deletion src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ protected function applySortClauses(Builder $query): void
?: ($this->sortBy ? $this->sortBy : optional($this->sortableColumns->first())->databaseDefaultColumn);
$this->sortDir = $this->request->sortDir
?: ($this->sortDir ? $this->sortDir : 'asc');
$query->orderBy($this->sortBy, $this->sortDir);
if ($this->sortBy && $this->sortDir) {
$query->orderBy($this->sortBy, $this->sortDir);
}
}

/**
Expand Down
19 changes: 16 additions & 3 deletions tests/Unit/SortTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@

class SortTest extends LaravelTableTestCase
{
public function testNoSortableAttribute()
{
$users = $this->createMultipleUsers(2);
$this->routes(['users'], ['index']);
$table = (new Table)->model(User::class)->routes(['index' => ['name' => 'users.index']]);
$table->column('name');
$table->column('email');
$table->render();
foreach ($users as $key => $user) {
$this->assertEquals($user->name, $table->list->items()[$key]['name']);
}
}

public function testSetSortableAttribute()
{
$table = (new Table)->model(User::class);
Expand Down Expand Up @@ -161,14 +174,14 @@ public function testSortableColumnHtml()
$table->column('name')->title('Name')->sortable();
$table->column('email')->title('Email');
$table->render();
$thead = view('laravel-table::' . $table->theadComponentPath, compact('table'))->render();
$html = view('laravel-table::' . $table->theadComponentPath, compact('table'))->render();
$this->assertStringContainsString(
'href="http://localhost/users/index?sortBy=name&sortDir=desc&rows=20"',
$thead
$html
);
$this->assertStringNotContainsString(
'href="http://localhost/users/index?sortBy=email&sortDir=desc&rows=20"',
$thead
$html
);
}
}

0 comments on commit 96ed523

Please sign in to comment.