Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6739645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:30:48+00:00 2026-05-26T11:30:48+00:00

Is there anyone knows how to extend the set_relation() ? Here is the idea,

  • 0

Is there anyone knows how to extend the set_relation() ?

Here is the idea, base on the example of Grocery Crud employee and offices tablesample table

$crud->set_relation('officeCode','offices','city');

the code output will show all city in dropdown, but I want to extent the set_relation() to filter all city by state to show in dropdown?

for example I want to show all city of Arizona state in dropdown, Does anyone done this before using grocery crud?

reference example:

Grocery Crud

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:30:49+00:00Added an answer on May 26, 2026 at 11:30 am

    I think you need this:

    function employees_management()
    {
        $crud = new grocery_CRUD();
    
        $crud->set_theme('datatables');
        $crud->set_table('employees');
        // add this line
        $crud->callback_edit_field('officeCode',array($this,'_call_back_offices'));
        $crud->callback_add_field('officeCode',array($this,'_call_back_offices'));
    
        $crud->display_as('officeCode','Office City');
        $crud->set_subject('Employee');
    
        $crud->set_relation('officeCode','offices','city');
    
        $output = $crud->render();
    
        $this->_example_output($output);
    }
    
    function _call_back_offices()
    {
        $this->load->model('user_model'); // your model
        $data = $this->user_model->getYou('offices','officeCode, city', "state = '".$this->session->userdata('state')."'"); // iam using session here
        $hasil ='<select name="officeCode">';
        foreach($data as $x)
        {
            $hasil .='<option value="'.$x->officeCode.'">'.$x->city.'</option>';
        }
        return $hasil.'</select>';
    }
    
    example user_model code:
    
    function getYou($tabel,$field = '*', $cond ='')
    {
        $this->db->select($field);
        $this->db->from($tabel);
        if(!empty($cond)) $this->db->where($cond);
        return $this->db->get()->result();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyone knows about list of web servers which is used in embedded
Is there anyone who knows this? I have been trying this for the last
Is there anyone who knows how to destroy a javascript (jquery) function? I'm using
Are there any tutorials or guides out there that anyone knows of that will
Anyone knows if there is an easy or known way to write a deep
Are there any replacements for NUnitAsp that anyone knows of for testing ASP.NET pages?
Anyone out there who knows what are the differences between BasicRenderEngine and LazyRenderEngine?
Does anyone know there have any other way that (by not using json_encode and
Does anyone know whether there's a way to mock Entity Data Provider so Unit
Does anyone know if there is a c# Console app, similar to the Python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.