Soru başlığı biraz komik oldu ama nasıl soracağımı bilemedim tam bir veri çekip db den ekrana basmaya çalışıyorum ecommerce projem de ama network de bu veriyi görmeme rağmen tabloya basamıyorum
Network çıktısı bu şekilde
https://prnt.sc/favjz0B-zGPh
https://prnt.sc/RbZYZTOJk0u4
buda tablo ekranım bir de neden sutunları 2 defa oluşturdu anlamadım.
Kodlarımı da paylaşayım
GPT İle çözemedik sabahtan beri 😃
Controllerım
public function index(ProductPriceTable $dataTable)
{
$this->pageTitle(trans('plugins/demo::index'));
// Assets::addScriptsDirectly('vendor/core/plugins/ecommerce/js/product-bulk-editable-table.js');
// dd($dataTable->renderTable()); // Bu satırı kaldırın veya yorum haline getirin
// return $dataTable->renderTable('plugins/demo::index');
return $dataTable->render('plugins/demo::index');
}
ProductPriceTable
<?php
namespace Botble\Demo\Tables;
use Botble\Demo\Models\Demo;
use Botble\Table\Columns\FormattedColumn;
use Botble\Table\Columns\IdColumn;
use Botble\Table\DataTables;
use Illuminate\Http\JsonResponse;
class ProductPriceTable extends ProductBulkEditableTable
{
public function setup(): void
{
parent::setup();
$this->setView('plugins/demo::index')
->addColumns([
IdColumn::make()
->title('ID')
->orderable(false)
->getValueUsing(function (IdColumn $column) {
return $column->getItem()->id;
}),
FormattedColumn::make('name')
->title(trans('plugins/demo::demo.name'))
->orderable(false)
->getValueUsing(function (FormattedColumn $column) {
return $column->getItem()->name;
}),
FormattedColumn::make('description')
->title(trans('plugins/demo::demo.description'))
->orderable(false)
->getValueUsing(function (FormattedColumn $column) {
return $column->getItem()->description;
}),
]);
}
public function query()
{
$query = Demo::query();
return $query;
}
public function ajax(): JsonResponse
{
$data = DataTables::of($this->query())
->editColumn('name', function($item) {
return $item->name;
})
->editColumn('description', function($item) {
return $item->description;
})
->make(true);
return response()->json($data);
}
}
ProductPriceBulkEditable
<?php
namespace Botble\Demo\Tables;
use Botble\Demo\Models\Demo;
use Botble\Table\Abstracts\TableAbstract;
use Botble\Table\Columns\FormattedColumn;
use Botble\Table\Columns\IdColumn;
use Botble\Table\DataTables;
use Illuminate\Http\JsonResponse;
abstract class ProductBulkEditableTable extends TableAbstract
{
protected int $pageLength = 100;
protected bool $hasResponsive = false;
public function hasColumnVisibilityEnabled(): bool
{
return false;
}
public function setup(): void
{
$this
->addColumns([
IdColumn::make()
->orderable(false)
->getValueUsing(function (IdColumn $column) {
return $column->getItem()->id;
}),
FormattedColumn::make('name')
->title(trans('plugins/demo::demo.name'))
->orderable(false)
->getValueUsing(function (FormattedColumn $column) {
return $column->getItem()->name;
}),
FormattedColumn::make('description')
->title(trans('plugins/demo::demo.description'))
->orderable(false)
->getValueUsing(function (FormattedColumn $column) {
return $column->getItem()->description;
}),
]);
}
public function query()
{
return Demo::query();
}
public function ajax(): JsonResponse
{
$data = DataTables::of($this->query())->make(true);
return response()->json($data);
}
protected function hasOperations(): bool
{
return false;
}
}
index
@extends(BaseHelper::getAdminMasterLayoutTemplate())
@section('content')
@include('core/table::base-table', ['table' => $table])
@endsection
Base-table.blade
@php
/** @var Botble\Table\Abstracts\TableAbstract $table */
@endphp
@once
@if ($randomHash = setting('datatables_random_hash'))
<script>window.DATATABLES_RANDOM_HASH = "{{ $randomHash }}";</script>
@endif
@endonce
{!! apply_filters(BASE_FILTER_TABLE_BEFORE_RENDER, null, $table) !!}
<div class="table-wrapper">
@if ($table->hasFilters())
<x-core::card
class="mb-3 table-configuration-wrap"
@style(['display: none' => !$table->isFiltering(), 'display: block' => $table->isFiltering()])
>
<x-core::card.body>
<x-core::button
type="button"
icon="ti ti-x"
:icon-only="true"
class="btn-show-table-options rounded-pill"
size="sm"
/>
{!! $table->renderFilter() !!}
</x-core::card.body>
</x-core::card>
@endif
<x-core::card @class([
'has-actions' => $table->hasBulkActions(),
'has-filter' => $table->hasFilters(),
])>
<x-core::card.header>
<div class="w-100 justify-content-between d-flex flex-wrap align-items-center gap-1">
<div class="d-flex flex-wrap flex-md-nowrap align-items-center gap-1">
@if ($table->hasBulkActions())
<x-core::dropdown
type="button"
:label="trans('core/table::table.bulk_actions')"
wrapper-class="d-inline-block"
>
@foreach ($table->getBulkActions() as $action)
{!! $action !!}
@endforeach
</x-core::dropdown>
@endif
@if ($table->hasFilters())
<x-core::button
type="button"
class="btn-show-table-options"
>
{{ trans('core/table::table.filters') }}
</x-core::button>
@endif
<div class="table-search-input">
<label>
<input type="search" class="form-control input-sm" placeholder="{{ trans('core/table::table.search') }}" style="min-width: 120px">
<button type="button" title="Search" class="search-icon"><x-core::icon name="ti ti-search" /></button>
<button type="button" title="Clear" class="search-reset-icon"><x-core::icon name="ti ti-x" /></button>
</label>
</div>
</div>
<div class="d-flex align-items-center gap-1">
@foreach($table->getButtons() as $button)
@if (Arr::get($button, 'extend') === 'collection')
<div class="dropdown d-inline-block">
<button class="btn buttons-collection dropdown-toggle {{ $button['className'] }}" data-bs-toggle="dropdown" tabindex="0" aria-controls="{{ $table->getOption('id') }}" type="button" aria-haspopup="dialog" aria-expanded="false">
{!! $button['text'] !!}
</button>
<div class="dropdown-menu">
@foreach($button['buttons'] as $buttonItem)
<button class="dropdown-item {{ $buttonItem['className'] }}">
{!! $buttonItem['text'] !!}
</button>
@endforeach
</div>
</div>
@else
<button class="btn {{ $button['className'] }}" tabindex="0" aria-controls="{{ $table->getOption('id') }}" type="button" aria-haspopup="dialog" aria-expanded="false">
{!! $button['text'] !!}
</button>
@endif
@endforeach
@foreach($table->getDefaultButtons() as $defaultButton)
@if (is_string($defaultButton))
@switch($defaultButton)
@case('reload')
<x-core::button
type="button"
data-bb-toggle="dt-buttons"
data-bb-target=".buttons-reload"
tabindex="0"
aria-controls="{{ $table->getOption('id') }}"
icon="ti ti-refresh"
>
{{ trans('core/base::tables.reload') }}
</x-core::button>
@break
@case('export')
<div class="dropdown">
<button title="{{ trans('core/base::tables.export') }}" class="btn buttons-collection dropdown-toggle buttons-export" data-bs-toggle="dropdown" tabindex="0" aria-controls="{{ $table->getOption('id') }}" type="button" aria-haspopup="dialog" aria-expanded="false">
<span>
<x-core::icon name="ti ti-download" /> {{ trans('core/base::tables.export') }}
</span>
</button>
<div class="dropdown-menu">
<button class="dropdown-item" data-bb-toggle="dt-exports" data-bb-target="csv" aria-controls="{{ $table->getOption('id') }}">
<span>
<x-core::icon name="ti ti-file-type-csv" /> {{ trans('core/base::tables.csv') }}
</span>
</button>
<button class="dropdown-item" data-bb-toggle="dt-exports" data-bb-target="excel" aria-controls="{{ $table->getOption('id') }}">
<span>
<x-core::icon name="ti ti-file-type-xls" /> {{ trans('core/base::tables.excel') }}
</span>
</button>
</div>
</div>
@break
@case('visibility')
@break(! Auth::user() instanceof \Botble\ACL\Models\User || ! AdminHelper::isInAdmin(true))
<div class="dropdown" data-bb-toggle="dt-columns-visibility-dropdown" aria-controls="{{ $table->getOption('id') }}">
<button title="{{ trans('core/base::tables.toggle_columns') }}" class="btn buttons-collection dropdown-toggle buttons-visibility" data-bs-toggle="dropdown" data-bs-auto-close="outside" tabindex="0" aria-controls="{{ $table->getOption('id') }}" type="button" aria-haspopup="dialog" aria-expanded="false">
<span>
<x-core::icon name="ti ti-columns-3" />
</span>
</button>
<div class="dropdown-menu p-2">
<x-core::form :url="route('table.update-columns-visibility')" method="PUT" data-bb-toggle="dt-columns-visibility">
<input type="hidden" name="table" value="{{ $table::class }}" />
@foreach($table->getColumns() as $column)
@php /** @var \Botble\Table\Columns\Column $column */ @endphp
@continue(Str::contains($column->className, 'no-column-visibility') || in_array($column->name, $table->getDefaultVisibleColumns(), true))
{{ Form::onOffCheckbox("columns_visibility[{$column->name}]", $table->determineIfColumnIsVisible($column), ['label' => $column->titleAttr ?: $column->title, 'data-bb-toggle' => 'dt-columns-visibility-toggle']) }}
@endforeach
</x-core::form>
</div>
</div>
@break
@endswitch
@endif
@endforeach
</div>
</div>
</x-core::card.header>
<div class="card-table">
<div @class([
'table-responsive',
'table-has-actions' => $table->hasBulkActions(),
'table-has-filter' => $table->hasFilters(),
])>
@section('main-table')
{!! $dataTable->table(compact('id', 'class'), false) !!}
@show
</div>
</div>
</x-core::card>
</div>
{!! apply_filters(BASE_FILTER_TABLE_AFTER_RENDER, null, $table) !!}
@push('footer')
@include('core/table::modal')
{!! $dataTable->scripts() !!}
{!! apply_filters(BASE_FILTER_TABLE_FOOTER_RENDER, null, $table) !!}
@endpush