I have a custom reporting feature I'm trying to build. To keep it short, the user is presented with options to choose from, those options are used to build an Eloquent query that returns data from the database to the front-end, in the form of an HTML table.
I'd like to switch my HTML table out for a Livewire Datatable. To do this, I need to build columns on the fly, based on what the user selects from the filters.
The datatable:
// $cols contains all the necesarry data from the user's selection to build columns the Livewire Datatable can understand.
public function displayReport($cols)
{
// This processes the data and pushes each new column into $this->cols
foreach($cols as $key => $val) {
$instance = app()->make($val['column']);
$columnName = $val['name'];
$item = $instance->name($columnName);
$item->filterable = true;
$item->hideable = true;
array_push($this->cols, $item);
}
public function columns()
{
return $this->cols;
}
I have dd($this->cols)
and it is exactly what is needed to build the datatable. The problem is with the refresh of the component (from what I can tell). Upon submitting the users selection and running the whole thing, I get the following error:
Despite my best troubleshooting efforts, I have not been able to get the table to hydrate properly upon submission of my new columns. I even put a dd($this->cols)
right before return $this->cols
in the column function, and it returns exactly what is expected. But it won't build the table, and it throws that error seen above.
Help is appreciated. Thank you so much. I know this is a weird and complex one.