KoolReport's Forum

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

Want to add a link to file from resource data table #2452

Open DVBI opened this topic on on Nov 22, 2021 - 1 comments

DVBI commented on Nov 22, 2021

Hi, I want to add a link to a column in resource datattable, that column is an image, I want to show the image on click of the image name, here is the code given below I am using

  protected function fields()
    {
        return [
            ID::create("id")
                ->showOnCreate(0)
                ->sortable(true),

            Text::create("name")
                ->validators([
                    RequiredFieldValidator::create()
                        ->errorMessage("Please enter name"),
                ])
                ->searchable(true)
                ->sortable(true),

            Text::create("upload_file")
                ->inputWidget(
                    FileUploader::create()
                        ->saveToFolder('uploads')
                        ->accept(["pdf", "csv", "jpg", "png"])
                        ->imagePreview(true)
                        ->previewWidth("100px")
                        ->previewHeight("100px")
                ),

            DateTime::create("created_at")
                ->baseFormat("Y-m-d H:i:s")->displayFormat("Y-m-d H:i:s")
                ->sortable(true),

            DateTime::create("updated_at")
                ->baseFormat("Y-m-d H:i:s")->displayFormat("Y-m-d H:i:s")
                ->sortable(true),
        ];
    }

I want to make upload_file as a link to that file, from data table in resource

    Text::create("upload_file")
                ->inputWidget(
                    FileUploader::create()
                        ->saveToFolder('uploads')
                        ->accept(["pdf", "csv", "jpg", "png"])
                        ->imagePreview(true)
                        ->previewWidth("100px")
                        ->previewHeight("100px")
                ),
KoolReport commented on Nov 22, 2021

You use the formatUsing():

Text::create("upload_file")
    ->formatUsing(function($value,$row){
        $text = $value;
        $link = $value; //Calculate the url link to the file here
         return "<a href='$link'>$text</a>";
    })

Hope that helps

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