Jump to content


Adding relation field in list view


  • Please log in to reply
1 reply to this topic

#1 nunenthal

nunenthal

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationFrance

Posted 17 July 2019 - 05: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);
        }   

 



#2 nunenthal

nunenthal

    Member

  • Members
  • PipPip
  • 27 posts
  • LocationFrance

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...






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users