LaCoder's avatar

YajraDatatables in Livewire component

I am using YajraDatatables in the controller and it's working fine, Below is the controller function, and it give me output in table,

class EodBhavDataController extends Controller
{
    //
    public function index(EodBhavDataTable $dataTable)
    {
        return $dataTable->render('pages/apps.eodbhavdata.list');
    }
}

and the same can be viewed in the blade below,

<div class="table-responsive">
    {{ $dataTable->table() }}
</div>

Now what I did in the Livewire component is below, I am passing component property to YajraDatatables EodBhavDataTable and getting $dataTable as query output.

//Livewire component file.

class Trades extends Component
{
    public $property;
    public $dataTable;

    public function mount($property)
    {
        $this->property = $property;
    }

    public function render(EodBhavDataTable $dataTable)
    {
        $this->dataTable = $this->property;
        $outputTable = $dataTable->render('pages/apps.eodbhavdata.list');
        
        return view('livewire.symbol.trades', ['table' => $outputTable]);
    }
}

//livewire.symbol.trades file.

<div class="table-responsive">
    {{ $table->table() }}
</div>

Now I want to output the same table via the Livewire blade, but it is not showing table output but shows an error Call to a member function table() on string

So the question is, how do we pass the YajraDatables render table via the Livewire component?

0 likes
3 replies
jlrdw's avatar

Curious as to why you would need the data tables in a component.

I'd suggest writing your own html table.

LaCoder's avatar

@jlrdw I have dataTable, which is getting used in two blade pages, one with full data and other which i used in component is with filtered data, so i passed at as component. What do you mean by writing own html table? Can you help me on that?

LaCoder's avatar

@jlrdw Ok. now I used @include to add the dataTable view and passed it via injection method,

    public function index($property, EodBhavDataTable $dataTable)
    {
        return $dataTable->render('pages/apps.symbol.overview', compact('property'));
    }

Its working fine now, without component

Please or to participate in this conversation.