⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Adding relation field in list view



nunenthal
  • profile picture
  • Member

Posted 17 July 2019 - 17:00 PM

Hello,

 

A simple problem.

I have set a relation with :

 

setRelation('categorie_id', 'categorie', 'nom_fr'

 

Ok it's perfect

 

I would like that categorie appear in list view like :

 

$crud->columns(['nom_fr2','nom_fr']);

 

But this don't work.

Is there a way ti do this ?

 

 

 

public function produits()
        {
        if ($this->session->aut != 1)
            exit;

        $crud = $this->_getGroceryCrudEnterprise();
        $crud->setTable('produits');
        $crud->setSubject('Produits', 'Produits');
        $crud->columns(['nom_fr2']);
        $crud->setLanguage('French');
        $crud->displayAs('nom_fr2', 'Nom de produit');
        $crud->displayAs('nom_en', 'Nom de produit en anglais');
        $crud->setRelation('categorie_id', 'categorie', 'nom_fr');
        $crud->unsetPrint();
        $crud->unsetExport();
        $output = $crud->render();
        $this->_header_admin_output($output);
        $this->load->view('admin_menu_v');
        $this->_admin_output($output);
        $this->_footer_admin_output($output);
        }   

 


nunenthal
  • profile picture
  • Member

Posted 18 July 2019 - 11:49 AM

As oftem all is in the documentation

 

Adding categorie_id in column

 

$crud->columns(['nom_fr2','categorie_id']);

 

and then use calbackColumn()

 

$crud->callbackColumn('categorie_id', function ($value, $row) {
        $query = $this->db->query("select * from categorie where id='$value'");
        $row = $query->row();
        return $row->nom_fr;
});

 

It's all...