Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jrdavidson's avatar

Yajra DataTable Package Passing In Additional Data for Add Column

I currently have three tables on one page that all are rendered with the yajra-laravel-datatables package. All three datatables contain an additional column for displaying the actions that can be taken on each model. What I want to be able to do is pass in an array of actions for each datatable action column so that in the `users.partials.action-cell if only does the checks for the actions for that datatable.

DataTable A - Employed Users - view, edit, delete, fire, etc.
DataTable B - Fired Users - view, edit, delete, rehire, etc.
DataTable C - Retired Users - view, edit, delete, rehire

Using the info above I want to be able to pass in only those actions for each DataTable class.

public function dataTable($query)
{
    return datatables($query)
        ->addColumn('action', 'users.partials.action-cell');
}
0 likes
2 replies
moharrum's avatar
moharrum
Best Answer
Level 6
public function dataTable($query)
{
    return datatables($query)
        ->addColumn('action', function() {
		// From here you may:

		// 1.  build your HTML
		$html = '<a href="#">LINK</a>';

		// 2. Render a view
		$view = view('users.partials.action-cell');

		$html = (string)$view;
		// or
		$html = $view->render();

		return $html;
	});
}
jrdavidson's avatar

@moharrum Okay perhaps I didn't explain well enough that there is an additional data like an actions variable I need to pass to the action-cell partial. I have the actions-cell blade file already written. I need to figure out how I can pass additoinal data in this way.

Please or to participate in this conversation.