KoolReport's Forum

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

Showing text from child table (foreign key) in dashboard table #3346

Closed Marloes opened this topic on on Oct 3 - 7 comments

Marloes commented on Oct 3

Hi,

Could you please point me in the right direction. I have a dashboard datagrid (table1) with a numeric foreign key column. In the details-page I can easily use the 'inputWidget' like below to show the corresponding description from "table2" in a selectionfield (on the primary key). But how do show this description in the column within the tablerow (datagrid table1) ? I tried to use Badge but could not find a way to show the values from the table2

->inputWidget(
                    Select::create()
                    ->dataSource(function(){
                        return AutoMaker::table("table2")
                                ->select("id, description");
                    })

With kind regards, Marloes

Sebastian Morales commented on Oct 4

How about in table1's dataSource you join the secondary table by the foreign key and select the description field, then set it to one of table1's columns? If we get your question wrong let us know.

KoolReport commented on Oct 4

Hi Marloes,

I guess you are using the admin panel from dashboard. In order to show extra information for table 1, you need to modify the query of Table 1 Resource to "join" the description from table 2.

You do that by modifying the "query()" function in resource. Let look at this example in which we join the Customer table into Order so that the Order Resource has the name of customer.

Example of joining table

Note: Please look at the Orders.php file which contains the "query()".

Please let us know if you need further assistance.

Marloes commented on Oct 4

Hi, thx for the reply. What I actually meant is that I have a table1 where I want to be able to alter a specific columnvalue which is a number (and also is the FK for table 2)... but I want it to be shown as the corresponding description-text. Let me explain with pictures:

This is what I have now, just focussing on the column named "Method" which contains the FK:

Figure 1.

And when clicking on edit I managed to show the corresponding text (description) to the FK with:

->inputWidget(
                    Select::create()
                    ->dataSource(function(){
                        return AutoMaker::table("table2")
                                ->select("id, description");
                    })

so that it shows me a dropdown to actually select the corresponding FK and change the value in the table1 row, see picture below: Figure 2.

And instead of showing the FK in the table like in figure 1, I want to show the description:

Sebastian Morales commented on Oct 4

I think your user case is similar to this demo page:

Dashboard Admin Order

In this admin page, table Orders is shown with foreign key CustomerNumber displayed/edited under CustomerName joined from table Customers. You could check below source code Order.php and OrderDetail.php to see how it is achieved.

Marloes commented on Oct 5

Thx for the reply. I tried that using "RelationLink::create" but that seems to need "->linkTo(DummyClass::class)" to be able to create a hyperlink which I don't want. Am I missing something?

Sebastian Morales commented on Oct 7

You can still use RelationLink field and make it look and behave like text instead of hyperlink:

            RelationLink::create("customerNumber")
                ->linkTo(Customer::class)
                ->cssClass('non-click-link') 

with these CSS rules (your_dashboard_theme.css):

.non-click-link {
    pointer-events: none;
    cursor: default;
    color: black;
}
Marloes commented on Oct 7

Thx Sebastian, that will do :-)

With kind regards, Marloes

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

DataGrid