|
@@ -2,10 +2,16 @@
|
|
|
|
|
|
namespace Dcat\Admin\Grid\Column;
|
|
|
|
|
|
+use Dcat\Admin\Grid;
|
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
|
|
|
|
class Sorter implements Renderable
|
|
|
{
|
|
|
+ /**
|
|
|
+ * @var Grid
|
|
|
+ */
|
|
|
+ protected $grid;
|
|
|
+
|
|
|
/**
|
|
|
* Sort arguments.
|
|
|
*
|
|
@@ -20,11 +26,6 @@ class Sorter implements Renderable
|
|
|
*/
|
|
|
protected $cast;
|
|
|
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- */
|
|
|
- protected $sortName;
|
|
|
-
|
|
|
/**
|
|
|
* @var string
|
|
|
*/
|
|
@@ -33,13 +34,13 @@ class Sorter implements Renderable
|
|
|
/**
|
|
|
* Sorter constructor.
|
|
|
*
|
|
|
- * @param string $sortName
|
|
|
+ * @param Grid $grid
|
|
|
* @param string $columnName
|
|
|
* @param string $cast
|
|
|
*/
|
|
|
- public function __construct($sortName, $columnName, $cast)
|
|
|
+ public function __construct(Grid $grid, $columnName, $cast)
|
|
|
{
|
|
|
- $this->sortName = $sortName;
|
|
|
+ $this->grid = $grid;
|
|
|
$this->columnName = $columnName;
|
|
|
$this->cast = $cast;
|
|
|
}
|
|
@@ -51,7 +52,7 @@ class Sorter implements Renderable
|
|
|
*/
|
|
|
protected function isSorted()
|
|
|
{
|
|
|
- $this->sort = app('request')->get($this->sortName);
|
|
|
+ $this->sort = app('request')->get($this->getSortName());
|
|
|
|
|
|
if (empty($this->sort)) {
|
|
|
return false;
|
|
@@ -60,6 +61,11 @@ class Sorter implements Renderable
|
|
|
return isset($this->sort['column']) && $this->sort['column'] == $this->columnName;
|
|
|
}
|
|
|
|
|
|
+ protected function getSortName()
|
|
|
+ {
|
|
|
+ return $this->grid->model()->getSortName();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return string
|
|
|
*/
|
|
@@ -86,11 +92,11 @@ class Sorter implements Renderable
|
|
|
|
|
|
if (! $this->isSorted() || $this->sort['type'] != 'asc') {
|
|
|
$url = request()->fullUrlWithQuery([
|
|
|
- $this->sortName => $sort,
|
|
|
+ $this->getSortName() => $sort,
|
|
|
]);
|
|
|
} else {
|
|
|
$url = request()->fullUrlWithQuery([
|
|
|
- $this->sortName => [],
|
|
|
+ $this->getSortName() => [],
|
|
|
]);
|
|
|
}
|
|
|
|