⚠ 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

Display related records of the current view/edit record



transitions
  • profile picture
  • Member

Posted 15 August 2013 - 12:47 PM

Hi

 

I'm quite new to grocery crud and couldn't find the answer to my problem in the docs, I guess grocery just doesn't support this yet:

 

When viewing or editing a record, I want to display related records of the current view/edit record on the same page.

 

To explain my issue, let's assume we have 2 database tables: Customers and Books, with the relation Customer hasMany Book and therefore Book belongsTo Customer.

When I click on View or Edit record in the Customer grocery table, I want to see another table (below the view/edit form) with all Books which are related with this Customer.

 

Isn't it an important feature of crud systems, to support related records for more than just mapping (as grocery crud is already capable of...)?

I wondered that this isn't implemented - or did I just not find it? ;)

 

Thank you!

Cheers

 

Similar question, but no replies: /topic/838-display-2-tables-parent-and-related-children-table/?hl=related


davidoster
  • profile picture
  • Member

Posted 15 August 2013 - 22:12 PM

Hello and welcome to the forums [member=transitions].

Well actually with the newest version stable of Grocery CRUD ver. 1.4 you have the option to display more than one tables on the same page.

With a little bit of javascript magic you could the result you are after but you won't get away without refreshing the page.

Basically what you're describing is a kind of Master/Details layout.

The multigrids is built for cases like the one you describe, but as it says on the examples is still in BETA.


redhen_07
  • profile picture
  • Member

Posted 16 August 2013 - 02:35 AM

@transitions, in your Customer Gc table you should add

 

 $crud->add_action('View', '', 'books','ui-icon-plus');

 

 

then in your controller add this

 

public function books($primary_key=NULL)

 

{

$crud = new grocery_CRUD();
      
    $crud->set_table('books');

 

    $crud-> where('custome_id',$primary_key); //this field the one related on your customer table

 

      $data = $this->db->get_where('customer',array('id'=>$primary_key))->row_array();

     

      $output = $crud->render();

        $output->output = '<div align="center"> <b>'."Below Book List". '</b></div>'.$output->output;
        $output->output = '<h1><div align="center"> <b>'.$data['lname'] .", " .$data['fname'].'</b></div></h1>'.$output->output;
            
                     $this->load->view('books',$output);

 

}

 

the output should be like this:

                                        lname, fname //the last name and fname of your customer

                                     Below Book List

 

then bellow is your GC tablw books that related to your custome..


davidoster
  • profile picture
  • Member

Posted 16 August 2013 - 15:42 PM

@transitions, in your Customer Gc table you should add

 

 $crud->add_action('View', '', 'books','ui-icon-plus');

 

 

then in your controller add this

 

public function books($primary_key=NULL)

 

{

$crud = new grocery_CRUD();
      
    $crud->set_table('books');

 

    $crud-> where('custome_id',$primary_key); //this field the one related on your customer table

 

      $data = $this->db->get_where('customer',array('id'=>$primary_key))->row_array();

     

      $output = $crud->render();

        $output->output = '<div align="center"> <b>'."Below Book List". '</b></div>'.$output->output;
        $output->output = '<h1><div align="center"> <b>'.$data['lname'] .", " .$data['fname'].'</b></div></h1>'.$output->output;
            
                     $this->load->view('books',$output);

 

}

 

the output should be like this:

                                        lname, fname //the last name and fname of your customer

                                     Below Book List

 

then bellow is your GC tablw books that related to your custome..

 

If I am not mistaken this replaces the whole view and just displays whatever comes from the books table. Isn't it?


transitions
  • profile picture
  • Member

Posted 16 August 2013 - 21:41 PM

Hello and welcome to the forums [member=transitions].

Well actually with the newest version stable of Grocery CRUD ver. 1.4 you have the option to display more than one tables on the same page.

With a little bit of javascript magic you could the result you are after but you won't get away without refreshing the page.

Basically what you're describing is a kind of Master/Details layout.

The multigrids is built for cases like the one you describe, but as it says on the examples is still in BETA.

 

Thanks for your replies!

You mean that I load the view/edit page and then fire an ajax request to load the table with the related records and append the response to the current page? Should work I guess... ;)

 

I've also heard of multigrids and that should work too... What I meant was that I think this should be possible out of the box :)

Cheers


davidoster
  • profile picture
  • Member

Posted 17 August 2013 - 17:25 PM

Multigrids as the stand now is the first step to get this functionality of master/detail out of the box!

Getting there slowly and hopefully soon enough.