data-table icon indicating copy to clipboard operation
data-table copied to clipboard

add row button on datatable

Open ksonia90 opened this issue 4 years ago • 0 comments

Hi, any idea on how to add row button based on DB column value? I planned to add it on Action column

so far this is my code:

  1. Controller:
<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Widgets\Callout;
use Illuminate\Support\Facades\DB;


class ReportController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->title($title = 'Report')
            ->row(function (Row $row) {

                $eval = DB::table('evaluations')
                    ->select('admin_users.name', DB::raw('count(evaluations.employee_evaluated) as total_evaluated'),'evaluations.employee_evaluated')
                    ->leftJoin('admin_users', 'admin_users.id', '=', 'evaluations.employee_evaluated')
                    ->groupBy('evaluations.employee_evaluated', 'admin_users.name')
                    ->orderBy('total_evaluated', 'DESC')
                    ->get('total_evaluated', 'admin_users.name');

                $OfficerEvaluatedSummary = view('admin.charts.OfficerEvaluatedSummary', compact('eval'));
                $row->column('12', new Box('Officer Evaluated Summary', $OfficerEvaluatedSummary));
            })->row(function (Row $row) {

                // $bar = view('admin.chartjs.doughnut');
                // $row->column(1/3, new Box('Doughnut chart', $bar));

                // $scatter = view('admin.chartjs.combo-bar-line');
                // $row->column(1/3, new Box('Chart.js Combo Bar Line Chart', $scatter));

                // $bar = view('admin.chartjs.line-stacked');
                // $row->column(1/3, new Box('Chart.js Line Chart - Stacked Area', $bar));

            });
    }
}

  1. Blade
<?php
use Jxlwqq\DataTable\DataTable;
// table
$headers = ['Employee Evaluated', 'Total Evaluation', 'Action'];
$rows = json_decode($eval);

 $style = ['table-bordered', 'table-hover', 'table-striped'];

$options = [
    'paging' => true,
    'lengthChange' => false,
    'searching' => true,
    'ordering' => true,
    'info' => true,
    'autoWidth' => true,
];

 $dataTable = new DataTable($headers, $rows, $style, $options);

echo $dataTable->render();

ksonia90 avatar Jul 06 '21 15:07 ksonia90