How to display different values on field & table column in grocery crud

3.1k views Asked by At

I want to display different values on field & table column. This is my code for dropdown values on field :

public function orders_management()
{
    try{
        $crud = new grocery_CRUD();

        $crud->set_table('order');
        $crud->set_subject('Order');
        $crud->display_as('software_list_fk','Software');
        $crud->set_relation('software_list_fk','software_list', '{software_name} | {part_number}');         

    }catch(Exception $e){
        show_error($e->getMessage().' --- '.$e->getTraceAsString());
    }
}

This works for my dropdown values, but I only want to display 'software_name' in table column not 'software name | part_number'. How to resolve that problem? Thanks in advance

1

There are 1 answers

0
rino.sukmandityo On BEST ANSWER

I have the answer from grocery crud forum (forum website)

And here is the complete code :

public function orders_management()
{
    try{
        $crud = new grocery_CRUD();

        $crud->set_table('order');
        $crud->set_subject('Order');
        $crud->display_as('software_list_fk','Software');

        if ($crud->getState() == 'add' OR $crud->getState() == 'edit')
        {
            $crud->set_relation('software_list_fk','software_list', '{software_name} | {part_number}');
        }
        else
        {
            $crud->set_relation('software_list_fk','software_list', 'software_name');
        }

    }catch(Exception $e){
        show_error($e->getMessage().' --- '.$e->getTraceAsString());
    }
}

It works..!!