KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Edit values of a table row #2627

Closed Peter Wendel opened this topic on on Apr 4, 2022 - 7 comments

Peter Wendel commented on Apr 4, 2022

Hi again!

I created a table to display the users of the website. It shows up correctly so far, but I did not get the way to connect one row oft that table to a modal, where I can edit the data of it. I'm kind of lost in your documentation.

Here ist the class of the table:

<?php

namespace App\KV\Dashboard\Tables;

use App\KV\Dashboard\DataSources\Web ;
use koolreport\dashboard\Client;
use koolreport\dashboard\fields\Boolean;
use koolreport\dashboard\fields\Button;
use koolreport\dashboard\fields\Date;
use koolreport\dashboard\fields\Number;
use koolreport\dashboard\fields\Text;

class UserTable extends \koolreport\dashboard\widgets\Table
{
    protected function onInit(){
        $this->tableStriped(true)
        ;
    }

    protected function dataSource()
    {
        return Web::table('users');
    }

    protected function fields(){
        return [
            Number::create('id')->useRaw(true)->label('User-ID'),
            Text::create('name')->label('Name'),
            Text::create('email')->label('Email'),
            Text::create('password')->label('Passwort'),
            Date::create('created_at')->baseFormat("Y-m-d H:i:s")->displayFormat('Y-m-d')->label('Zugelassen am'),
            Date::create('updated_at')->baseFormat("Y-m-d H:i:s")->displayFormat('Y-m-d')->label('Bearbeitet am'),
            Boolean::create('admin')->label('Admin'),
            Button::create('id')->label('')->type("warning")
                ->size("sm")
                ->outline(false)
                ->text("User bearbeiten")
                ->onClick(function($value,$row){
                    return Client::widget("UserTable")->action("edit",["id"=>$value]);
                }),
            Button::create('id')->label('')->type("danger")
                ->size("sm")
                ->outline(false)
                ->text("User löschen")
                ->onClick(function($value,$row){
                    return Client::widget("UserTable")->action("delete",["id"=>$value]);
                }),
        ];
    }

    protected function actionEdit($request,$response){
        //TODO User editieren
    }

    protected function actionDelete($request, $response){
        //TODO User löschen
    }
}

Can you point me a way to display a row in modal for editing saving it? Which way I have to go?

Thanks again for your help!

Peter

KoolReport commented on Apr 4, 2022

Dashboard is mostly for data visualization. However, in the latest version of Dashboard, we add a new cool feature for Dashboard which is called "admin panel", this allow crud. Maybe it will be what you are looking for. You can see how admin works from our demo. Let me know if you need further information.

Peter Wendel commented on Apr 4, 2022

So I created a "Resource" of the table.

<?php

namespace App\KV\Dashboard\Resource;

use App\KV\Dashboard\DataSources\Web;
use koolreport\dashboard\fields\Boolean;
use koolreport\dashboard\fields\Date;
use koolreport\dashboard\fields\ID;
use koolreport\dashboard\fields\Text;

class UserResource extends \koolreport\dashboard\admin\Resource
{
    protected function onCreated()
    {
        $this
            ->manageTable("users")      // Manage the table "users"
            ->inSource(Web::class)
        ;
    }

    protected function fields()
    {
        return [
            ID::create('id')->useRaw(true)->label('User-ID'),
            Text::create('name')->label('Name'),
            Text::create('email')->label('Email'),
            Text::create('password')->label('Passwort'),
            Date::create('created_at')->baseFormat("Y-m-d H:i:s")->displayFormat('Y-m-d')->label('Zugelassen am'),
            Date::create('updated_at')->baseFormat("Y-m-d H:i:s")->displayFormat('Y-m-d')->label('Bearbeitet am'),
            Boolean::create('admin')->label('Admin'),
        ];
    }
}

But it shows "oops" if I want to show this as a Dahsboard itself ain App.php.

protected function dashboards()
    {
        return [
            "Server"    => Section::create()->sub([
                "DB-Monitor"      => HomeBoard::create()->icon('fa fa-database'),
                "AVD-Portal-User" => UserResource::create()->icon('fa fa-user'),
            ]),

            "Arzneimittel"  => Section::create()->sub([

            ]),
            "Heilmittel"    => Section::create()->sub([
                'Datenstand HM'        => HmDsBoard::create()->icon('fa fa-database'),
                'STD-Verarbeitung'  => Group::create()->icon('fa fa-folder')->sub([
                    "STD-Datei-Verwaltung" => HmStdBoard::create()->icon('fa fa-file')
                ]),
                'HMD-Verarbeitung' => Group::create()->icon('fa fa-folder')->sub([
                    "HMD-Datei-Verwaltung" => HmHmdBoard::create()->icon('fa fa-file'),
                    ]),
                ]),
        ];
    }

as you do in your demo or documentation. What's wrong?

KoolReport commented on Apr 4, 2022

Please turn on the debugMode inside App.php so that you know what went wrong:

class App extends Application
{
    protected function onCreated()
    {
        $this
        ...
        ->debugMode(true)
        ...
    }
}
Peter Wendel commented on Apr 4, 2022

Okay. Got it running so far :-) Thanks for your help in that point.

We have tables of config-data that may change e.g. from one year to another. And always there are only some of them, that must be changed. So we use to copy that data from the year before and were editing the bunch of them with changes afterwards. On database the copying is as simple as that:

insert into  table config (year,my_config, config_value)
select '2022', my_config, config_value from config where year=2021;

I think I can add a button for that operation somewhere to the admin panel, but I'm not sure where to start: Would this be an action to add? Or is it a glass for creating this?

What would you suggest to do?

KoolReport commented on Apr 4, 2022

If you want to add Button on top of admin Table, you may use the highlight something like this:

class Customer extends Resource
{
    protected function highlights()
    {
        return [
            Panel::create()->header("Utility")->type("primary")->sub([
                CopyButton::create()
            ])
            ...
        ];
    }
}

Your CopyButton is derived from "inputs/Button" (be careful not to confuse with fields/Button). There in the CopyButton, you can define what happens when that button is clicked.

Inside the actionSubmit of CopyButton, you can run raw query:

Web::rawSQL("your query")->run();

Hope that helps.

Peter Wendel commented on Apr 4, 2022

Okay, that sounds easy.

So at least there is this little last question: Where can I put another value for the amouunt of rows displayed on one page of the paging in the admin panel?

Thanks again for your friendly help!

Peter

KoolReport commented on Apr 4, 2022

You are welcome :). Inside the onCreated of UserResource, you do:

$this->listScreen()->adminTable()->pageSize(20);

For your reference.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

Dashboard