Select field showing more than one column from another table

Select field showing more than one column from another table

daniloragodanilorago Posts: 26Questions: 8Answers: 0

Hello All,

I want to know if it's possible to show more than on column from another table inside a dropdown select list.
For example, I have the table Customer, with first and last name separated, then I have the sales table, that I can select in a dropdown list the customer, but I need to see on this dropdown list both names. How can I do that?

Thanks in advance!

BR,
Danilo

Answers

  • allanallan Posts: 64,301Questions: 1Answers: 10,618 Site admin

    Hi Danilo,

    Can you provide a little more information please? For example is this using an Editor form? Can you post a screenshot of what you currently have? I'm not quite managing to picture it at the moment I'm afraid.

    Allan

  • daniloragodanilorago Posts: 26Questions: 8Answers: 0

    Actually, yes, I am using the editor.
    I don't have anything ready yet or I'm trying to do it, but let's suppose I have:
    Table: Customer
    Field: Customer ID
    Field: First Name
    Field: Last Name

    Table: Sales
    Field: Sales ID
    Field: Customer ID

    In the form where I have to register a sale, using the Sales table, I would like the dropdown field (select type field) that has the Customer ID to show a combination of the First and Last Name fields

    Have I made myself clearer now?
    Thank you very much in advance...

  • allanallan Posts: 64,301Questions: 1Answers: 10,618 Site admin

    Yes! Many thanks for the clarification.

    You just need to specify the ->label() method for the Options instance for that field with the two columns you want (assuming you are using the provided PHP, .NET or Node.js libraries?).

    There is an example of this here - specifically in the PHP:

            Field::inst( 'users.manager' )
                ->options( Options::inst()
                    ->table( 'users' )
                    ->value( 'id' )
                    ->label( array('first_name', 'last_name') )
                ),
    

    See the Options->label() documentation for more details.

    Allan

Sign In or Register to comment.