KoolReport's Forum

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

How to distinguish between screens? #2842

Open jernej opened this topic on on Oct 4, 2022 - 1 comments

jernej commented on Oct 4, 2022

In Admin Panel, I have created a custom field extending from \koolreport\dashboard\Field with a custom render file (.view.php). But I have to show a slightly different version in list screen, in update screen and in create screen (so each screen will have a bit different version of a field).

My question is: how do I know in my .view.php (or in class extending from dashboard\field) on which screen I currently am? Or is there some other way of doing this?

Thank you

KoolReport commented on Oct 5, 2022

A simple way to complete your idea is to create multiple same field and turn it on or off for each screen. You add a property "dedicatedScreen" to your custom field. And then you do this:


protected function fields()
{
    return [
        MyField::create("myColumn")
        ->dedicatedScreen("update")
        ->showOnAll(false)
        ->showOnUpdate(true),

        MyField::create("myColumn")
        ->dedicatedScreen("index")
        ->showOnAll(false)
        ->showOnIndex(true),

        MyField::create("myColumn")
        ->dedicatedScreen("create")
        ->showOnAll(false)
        ->showOnCreate(true),

        MyField::create("myColumn")
        ->dedicatedScreen("detail")
        ->showOnAll(false)
        ->showOnDetail(true),
    ];
}

Now in the view or anywhere in the MyField class, you can access the dedicatedScreen() to know where it is.

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

Dashboard