1: <?php
2:
3: declare(strict_types=1);
4:
5: namespace Atk4\Ui\Table\Column;
6:
7: use Atk4\Data\Field;
8: use Atk4\Ui\Js\JsExpressionable;
9: use Atk4\Ui\JsSortable;
10: use Atk4\Ui\Table;
11: use Atk4\Ui\View;
12:
13: /**
14: * Implement drag handler column for sorting table.
15: */
16: class DragHandler extends Table\Column
17: {
18: /** @var string */
19: public $class;
20: /** @var string */
21: public $tag = 'i';
22: /** @var JsSortable */
23: public $cb;
24:
25: #[\Override]
26: protected function init(): void
27: {
28: parent::init();
29:
30: if (!$this->class) {
31: $this->class = 'content icon';
32: }
33: $this->cb = JsSortable::addTo($this->table, ['handleClass' => 'atk-handle']);
34: }
35:
36: /**
37: * Callback when table has been reorder using handle.
38: *
39: * @param \Closure(list<string>, string, int, int): (JsExpressionable|View|string|void) $fx
40: */
41: public function onReorder(\Closure $fx): void
42: {
43: $this->cb->onReorder($fx);
44: }
45:
46: #[\Override]
47: public function getDataCellTemplate(Field $field = null): string
48: {
49: return $this->getApp()->getTag($this->tag, ['class' => $this->class . ' atk-handle', 'style' => 'cursor:pointer; color: #bcbdbd']);
50: }
51: }
52: