Skip to content

Commit

Permalink
update table tree functional
Browse files Browse the repository at this point in the history
  • Loading branch information
agoalofalife committed Mar 25, 2024
1 parent acb2914 commit 8f54f19
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion public/js/orchid_fields.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions resources/js/controllers/table-tree_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ export default class extends window.Controller {
const hiddenColumns = JSON.parse(localStorage.getItem(this.slug));

this.hiddenColumns = hiddenColumns || [];

// remove preloader
document.getElementById('table-tree-loader').classList.add('d-none');
document.getElementById('table-tree').classList.remove('d-none');

}

/**
*
*/
connect() {

this.allowDefaultHidden();
this.renderColumn();

Expand Down
11 changes: 8 additions & 3 deletions resources/views/layouts/tree-table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
data-table-slug="{{$slug}}"
>

<div class="table-responsive">
<div id="table-tree-loader" class="d-flex justify-content-center align-items-center" style="height: 400px">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>

<div class="table-responsive d-none" id="table-tree" >
<table @class([
'table',
'tree-table',
Expand All @@ -32,12 +38,11 @@
</tr>
</thead>
@endif

<tbody>

@foreach($rows as $source)
<tr
@if($source->getContent('parent') === $source->getContent($nameId) )
@if($source->getContent('parent') === $source->getContent($nameId))
data-node-id="{{ $source->getContent($nameId) }}"
@else
data-node-id="{{ $source->getContent($nameId) }}" data-node-pid="{{ $source->getContent('parent') }}"
Expand Down
14 changes: 6 additions & 8 deletions resources/views/partials/layouts/td.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<td class="text-{{$align}} @if(!$width) text-truncate @endif"
{{-- data-column="{{ $slug }}"--}}
colspan="{{ $colspan }}"
style="
@empty(!$width)
min-width:{{ is_numeric($width) ? $width . 'px' : $width }};
@endempty
@if($isFirst)
display:flex;
@endif
"
@style([
"min-width:$width;" => $width,
"$style" => $style,
"display:flex" => $isFirst
])
>
<div style="padding-left: 2%">
@isset($render)
Expand Down
8 changes: 2 additions & 6 deletions src/Layouts/TreeTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@ class TreeTable extends Table
* @var string
*/
protected $template = 'platform-fields::layouts.tree-table';

public function __construct(string $target, protected array $columns, protected $nameId = 'id')
{
$this->target = $target;
}
protected $nameId = 'id';

protected function columns(): iterable
{
return $this->columns;
return [];
}

public function build(Repository $repository)
Expand Down
23 changes: 21 additions & 2 deletions src/OrchidFieldsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\ServiceProvider;
use Orchid\Platform\Dashboard;
use Orchid\Screen\LayoutFactory;
use Orchid\Screen\Layouts\Table;

class OrchidFieldsServiceProvider extends ServiceProvider
{
Expand All @@ -25,8 +26,26 @@ public function boot(Dashboard $dashboard): void
$dashboard->registerResource('stylesheets', 'https://cdnjs.cloudflare.com/ajax/libs/ion-rangeslider/2.3.1/css/ion.rangeSlider.min.css');

// tree table https://www.jqueryscript.net/table/simple-tree-table.html
LayoutFactory::macro('tableTree', function ($key, $columns, $nameId = 'id') {
return new TreeTable($key, $columns, $nameId);
LayoutFactory::macro('treeTable', function (string $target, array $columns, string $nameId = 'id') {
return new class($target, $columns, $nameId) extends TreeTable
{
/**
* @var array
*/
protected $columns;

public function __construct(string $target, array $columns, string $nameId)
{
$this->target = $target;
$this->columns = $columns;
$this->nameId = $nameId;
}

public function columns(): array
{
return $this->columns;
}
};
});
$this->registerAssets();
}
Expand Down

0 comments on commit 8f54f19

Please sign in to comment.