Skip to content

Commit

Permalink
Merge branch '9.0'
Browse files Browse the repository at this point in the history
* 9.0:
  Bump v9.12.0 🚀
  Update license to 2020
  "Register provider and facade" is optional in 5.5 and newer
  Add support FALSE to orderColumn.
  Fix laravel version & badge.
  Bump v9.11.1 🚀
  fix copy/paste whitespace error
  add test case for sorting numeric values
  Use lt/gt checking when both values are numeric
  • Loading branch information
yajra committed Oct 31, 2020
2 parents 12f4bf8 + 0fbc3ba commit b1bb78f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 7 deletions.
20 changes: 19 additions & 1 deletion CHANGELOG.md
Expand Up @@ -8,6 +8,16 @@

### [Unreleased]

### [v9.12.0] - 2020-10-31

- Add disable ordering via orderColumn. [#2481], credits to [@gredimano]
- Fix [#1953]

### [v9.11.1] - 2020-10-06

- Use simple numeric sorting when dealing with numeric values [#2478], credits to [@miken32]
- Fix [#1934].

### [v9.11.0] - 2020-09-09

- Add support for Laravel 8. [#2457] by [@lloricode]
Expand Down Expand Up @@ -389,7 +399,9 @@ return (new CollectionDataTable(User::all())->toJson();
- Fix orderColumn api where related tables are not joined.
- Fix nested with relation search and sort function.

[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v9.11.0...9.0
[Unreleased]: https://github.com/yajra/laravel-datatables/compare/v9.12.0...9.0
[v9.12.0]: https://github.com/yajra/laravel-datatables/compare/v9.11.1...v9.12.0
[v9.11.1]: https://github.com/yajra/laravel-datatables/compare/v9.11.0...v9.11.1
[v9.11.0]: https://github.com/yajra/laravel-datatables/compare/v9.10.2...v9.11.0
[v9.10.2]: https://github.com/yajra/laravel-datatables/compare/v9.10.1...v9.10.2
[v9.10.1]: https://github.com/yajra/laravel-datatables/compare/v9.10.0...v9.10.1
Expand Down Expand Up @@ -530,7 +542,10 @@ return (new CollectionDataTable(User::all())->toJson();
[#2391]: https://github.com/yajra/laravel-datatables/pull/2391
[#2382]: https://github.com/yajra/laravel-datatables/pull/2382
[#2414]: https://github.com/yajra/laravel-datatables/pull/2414
[#2478]: https://github.com/yajra/laravel-datatables/pull/2478
[#2481]: https://github.com/yajra/laravel-datatables/pull/2481

[#1934]: https://github.com/yajra/laravel-datatables/issues/1934
[#2091]: https://github.com/yajra/laravel-datatables/issues/2091
[#2058]: https://github.com/yajra/laravel-datatables/issues/2058
[#1626]: https://github.com/yajra/laravel-datatables/issues/1626
Expand Down Expand Up @@ -569,6 +584,7 @@ return (new CollectionDataTable(User::all())->toJson();
[#2202]: https://github.com/yajra/laravel-datatables/issues/2202
[#1975]: https://github.com/yajra/laravel-datatables/issues/1975
[#1747]: https://github.com/yajra/laravel-datatables/issues/1747
[#1953]: https://github.com/yajra/laravel-datatables/issues/1953

[laravel-datatables-fractal]: https://github.com/yajra/laravel-datatables-fractal

Expand Down Expand Up @@ -610,3 +626,5 @@ return (new CollectionDataTable(User::all())->toJson();
[@ehsanrasta]: https://github.com/ehsanrasta
[@mgralikowski]: https://github.com/mgralikowski
[@edwwaarrdd]: https://github.com/edwwaarrdd
[@miken32]: https://github.com/miken32
[@gredimano]: https://github.com/gredimano
2 changes: 1 addition & 1 deletion LICENSE.md
@@ -1,6 +1,6 @@
(The MIT License)

Copyright (c) 2013-2019 Arjay Angeles <aqangeles@gmail.com>
Copyright (c) 2013-2020 Arjay Angeles <aqangeles@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -4,7 +4,7 @@
[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg)](https://www.paypal.me/yajra)
[![Donate](https://img.shields.io/badge/donate-patreon-blue.svg)](https://www.patreon.com/bePatron?u=4521203)

[![Laravel 4.2|5.x|6.x](https://img.shields.io/badge/Laravel-4.2|5.x-orange.svg)](http://laravel.com)
[![Laravel 4.2|5.x|6|7|8](https://img.shields.io/badge/Laravel-4.2|5.x|6|7|8-orange.svg)](http://laravel.com)
[![Latest Stable Version](https://img.shields.io/packagist/v/yajra/laravel-datatables-oracle.svg)](https://packagist.org/packages/yajra/laravel-datatables-oracle)
[![Latest Unstable Version](https://poser.pugx.org/yajra/laravel-datatables-oracle/v/unstable.svg)](https://packagist.org/packages/yajra/laravel-datatables-oracle)
[![Build Status](https://travis-ci.org/yajra/laravel-datatables.svg?branch=master)](https://travis-ci.org/yajra/laravel-datatables)
Expand All @@ -30,7 +30,7 @@ return datatables(User::all())->toJson();

## Requirements
- [PHP >= 7.0](http://php.net/)
- [Laravel 5.x|6.x](https://github.com/laravel/framework)
- [Laravel 4.2|5.x|6|7|8](https://github.com/laravel/framework)
- [jQuery DataTables v1.10.x](http://datatables.net/)

## Documentations
Expand Down Expand Up @@ -60,6 +60,7 @@ return datatables(User::all())->toJson();
5.8.x | 9.x
6.x.x | 9.x
7.x.x | 9.x
8.x.x | 9.x

## DataTables 8.x Upgrade Guide
There are breaking changes since DataTables v8.x.
Expand All @@ -70,7 +71,7 @@ If you are upgrading from v7.x to v8.x, please see [upgrade guide](https://yajra
$ composer require yajra/laravel-datatables-oracle:"~9.0"
```

#### Service Provider & Facade (Optional on Laravel 5.5)
#### Service Provider & Facade (Optional on Laravel 5.5+)
Register provider and facade on your `config/app.php` file.
```php
'providers' => [
Expand Down
10 changes: 9 additions & 1 deletion src/CollectionDataTable.php
Expand Up @@ -294,7 +294,15 @@ protected function getSorter(array $criteria)
$first = $a;
$second = $b;
}
if ($this->config->isCaseInsensitive()) {
if (is_numeric($first[$column] ?? null) && is_numeric($second[$column] ?? null)) {
if ($first[$column] < $second[$column]) {
$cmp = -1;
} elseif ($first[$column] > $second[$column]) {
$cmp = 1;
} else {
$cmp = 0;
}
} elseif ($this->config->isCaseInsensitive()) {
$cmp = strnatcasecmp($first[$column] ?? null, $second[$column] ?? null);
} else {
$cmp = strnatcmp($first[$column] ?? null, $second[$column] ?? null);
Expand Down
6 changes: 5 additions & 1 deletion src/QueryDataTable.php
Expand Up @@ -671,11 +671,15 @@ protected function hasOrderColumn($column)
* Apply orderColumn custom query.
*
* @param string $column
* @param array $orderable
* @param array $orderable
*/
protected function applyOrderColumn($column, $orderable)
{
$sql = $this->columnDef['order'][$column]['sql'];
if ($sql === false) {
return;
}

if (is_callable($sql)) {
call_user_func($sql, $this->query, $orderable['direction']);
} else {
Expand Down
42 changes: 42 additions & 0 deletions tests/Integration/CollectionDataTableTest.php
Expand Up @@ -130,6 +130,48 @@ public function it_can_sort_case_insensitive_strings()
], $response->getData(true));
}

/** @test */
public function it_can_sort_numeric_strings()
{
config()->set('app.debug', false);
request()->merge([
'columns' => [
['data' => 'amount', 'name' => 'amount', 'searchable' => 'true', 'orderable' => 'true'],
],
'order' => [['column' => 0, 'dir' => 'asc']],
'start' => 0,
'length' => 10,
'draw' => 1,
]);

$collection = collect([
['amount' => '12'],
['amount' => '7'],
['amount' => '-8'],
['amount' => '0'],
['amount' => '-3'],
['amount' => '8'],
]);

$dataTable = app('datatables')->collection($collection);
/** @var JsonResponse $response */
$response = $dataTable->toJson();

$this->assertEquals([
'draw' => 1,
'recordsTotal' => 6,
'recordsFiltered' => 6,
'data' => [
['amount' => '-8'],
['amount' => '-3'],
['amount' => '0'],
['amount' => '7'],
['amount' => '8'],
['amount' => '12'],
],
], $response->getData(true));
}

/** @test */
public function it_accepts_a_model_using_ioc_container_factory()
{
Expand Down

0 comments on commit b1bb78f

Please sign in to comment.