⚠ 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

Simple dependant dropdown extension



venkatesh
  • profile picture
  • Member

Posted 30 March 2018 - 03:54 AM

well my friend - u have every where clause possible in set_relation.. now why all of a sudden u need a where clause in set_relation_dependancy?

I am in the same situation .In set relation the where condition works fine,but it doesnt retrieve the same records based on where condition in set relation for set relation dependency. 

This is my code

 

$crud->set_relation('CONTRY_CODE','contry','CONTRY_NAME',array('CONTRY_STATUS' => 'E'));
 $crud->set_relation('STATE_CODE','state','STATE_NAME',array('STATE_STATUS' => 'E'));
 $crud->set_relation('CITY_CODE','city','CITY_NAME',array('CITY_STATUS' => 'E'));
 $crud->set_relation_dependency('STATE_CODE','CONTRY_CODE','CONTRY_CODES',array('STATE_STATUS' => 'E'));
 $crud->set_relation_dependency('CITY_CODE','STATE_CODE','CITY_STATE_CODE');
 
when i click on state code it returns only the states for which status are enabled.But when I select country,then state(due to dependency) it retrieves all the state records (even disabled status records).
 
Can anyone please suggest any possible solution??

avi
  • profile picture
  • Member

Posted 11 April 2018 - 03:29 AM

 

Well this if i am not mistakened - this one you talking about i edit and not add. I do understand the situation - i faced it mysef. Even for add - it just shows all the entries at the first instance.. This has been a drawback of the plugin but fortunately i found a way around for the same.

 

i have had the same scenario for add / edit drop down dependency for country / state / city

 

i am sharing u my piece of code - it might help u understand a solution for the same

$crud->set_relation('country', 'countries', 'country_name');				
		$segments = $this->uri->segments;
		$segmentFound = false;
		foreach($segments as $num => $value) {
			if($value == 'ajax_extension') {
				$segmentFound = true;
				break;
			}
		}
		if($segmentFound) {
			$crud->set_relation('city', 'cities', 'city_name');
			$crud->set_relation('state', 'states', 'state_name');
		} else {
			if($crud->getState() == 'edit') {
				//$pk = $crud->getStateInfo()->primary_key;
				//$row = $this->cModel->getByField('retailers', 'rid', $pk);
				if($curRow['country'] != '') {
					$allstates = $this->cModel->getAllFor('states', 'country_code', $curRow['country']);
					$states = array('1'=>'select state');
					foreach ($allstates as $state) {
						$states[$state['state_code']] = $state['state_name'];
					}
				}
				
				$state_code = $curRow['state'];
				if($state_code != '') {
					$allcities = $this->cModel->getAllFor('cities', 'state_code', $state_code);
					$cities = array('1'=>'select city');
					foreach ($allcities as $city) {
						$cities[$city['city_code']] = $city['city_name'];
					}
				} else {
					$cities = array('1'=>'select city');	
				}
				
				if($curRow['country'] == '') {
					$cities = array('1'=>'select state');
				}
			} else {
				$cities = array('1'=>'select city');
				$states = array('1'=>'select state');
			}
			$crud->field_type('city', 'dropdown', $cities);
			$crud->field_type('state', 'dropdown', $states);
		}

Dear Amit,

 

I hope you are well :)

 

I'm experiencing the same problem you had years ago, i'm trying to understand your solution here.. can you possibly post the complete code for your solution above? Where do you implement the set_relation_dependency part?

 

The library is loading the whole list of complete dropdown items when adding new items so it become so slow. and also at edit situation, it also loads the whole list..


analuthfa
  • profile picture
  • Member

Posted 02 May 2018 - 01:03 AM

Hi all, i'm new in GC. i have used library ajax_grocery_crud for dependant dropdown, but the second dropdown not filtering value based on first selected dropdown value.

Here is my code

 

public function surat()
    {

 

$template = $this->Surat_model->get_template();

 

$this->load->library('ajax_grocery_crud');
        $crud = new ajax_grocery_CRUD();
        $crud->set_theme('bootstrap');
        $crud->set_table('surat');
        $crud->set_relation('jenis_surat_id','jenis_surat','jenis_surat');
        $crud->display_as('jenis_surat_id','Jenis Surat');
        $crud->set_relation('kode_klasifikasi','klasifikasi_surat','nama_klasifikasi');
        $crud->display_as('kode_klasifikasi','Klasifikasi');
        
        $crud->set_relation('sub_klas_id','sub_klasifikasi_surat','nama_subklas');
        $crud->display_as('sub_klas_id','');
        
        $crud->set_relation_dependency('sub_klas_id','kode_klasifikasi','kode_klasifikasi');
        
        $crud->set_relation('sub_subklas_id','sub_sub_klasifikasi_surat','nama_sub_subklas');
        $crud->display_as('sub_subklas_id','');
        
        $crud->set_relation_dependency('sub_subklas_id','sub_klas_id','sub_klas_id');
        
        $this->load->library('gc_dependent_select');
        
        $crud->set_primary_key('nipp','pegawai');
        $crud->set_relation('pengirim','pegawai','employee_name');
        $crud->display_as('pengirim','Pengirim');
        $crud->set_field_upload('lampiran','assets/uploads/files');
        $crud->set_relation_n_n('penerima', 'detil_penerima', 'pegawai', 'id_surat', 'nipp', 'employee_name');
        $crud->set_relation_n_n('tembusan', 'detil_tembusan', 'pegawai', 'id_surat', 'nipp', 'employee_name');
        $crud->set_relation_n_n('pemeriksa', 'detil_pemeriksa', 'pegawai', 'id_surat', 'nipp', 'employee_name');
        $crud->change_field_type('dibuat_oleh','invisible');
        $crud->unset_texteditor('catatan');
        $crud->unset_fields('no_urut','pengirim','divisi_pengirim','revisi','status');
        
        $crud->columns('tgl_surat','perihal','pengirim','dibuat_oleh','penerima');
        $crud->fields('jenis_surat_id','kode_klasifikasi','sub_klas_id','sub_subklas_id','tgl_surat','perihal','isi_surat','lampiran','prioritas','keamanan','pengirim','penerima','tembusan','pemeriksa','catatan');
        
      
            $output = $crud->render();
           
            $output->extra = $template;
            $this->_home_output($output);

}

 

thanks in advance


kingwash
  • profile picture
  • Member

Posted 23 January 2019 - 10:57 AM

Thank you so much Mr ricardomduarte for you awesome library.

I tried to use your library with Grocory CURD 1.4.0 but I got this error message

Fatal error: Access level to ajax_grocery_CRUD::$state_code must be protected (as in class Grocery_CRUD) or weaker in C:\wamp\www\cpuwebsite\application\libraries\ajax_grocery_crud.php on line 255
Go "application\libraries\ajax_grocery_crud.php" open the file and change "private $state_code  = null;"   to  protected $state_code  = null;
 

please any idea about it, let me know i will be waiting


kingwash
  • profile picture
  • Member

Posted 23 January 2019 - 10:58 AM

Fatal error: Access level to ajax_grocery_CRUD::$state_code must be protected (as in class Grocery_CRUD) or weaker in C:\wamp\www\cpuwebsite\application\libraries\ajax_grocery_crud.php on line 255

 

 

 

Answer

Go to "application\libraries\ajax_grocery_crud.php" open the file and change "private $state_code = null;" to protected $state_code = null;


Ralph
  • profile picture
  • Member

Posted 07 August 2020 - 15:09 PM

Hi im a newbie to grocery crud. I need the functionality of ajax_grocery_crud. I took php file updated by Amit Shah and made that trigger('chosen:updated') to  trigger("liszt:updated") on function 'render_relation_dependency' in  ajax_grocery_crud.php modification. It does not act as expected, the dependant selector is not restricted to the selection from the independant dropdown. It does not do any harm anyway, just as it would not be there. The grocery_CRUD library is loaded in the constructor. The language of GC is still english. Here is my code:

 

    public function component_parts() {
    
        $this->session->header = 'Tabelle: Bauteile der Komponente';  // German language
        
        try{
            $this->load->library('ajax_grocery_CRUD');
            $crud = new ajax_grocery_CRUD();
            $crud->set_theme('datatables');
            
            $crud->set_table('partlist');
            $crud->set_subject('Bauteil');
            $crud->columns('conr','paclassnr','panr','quantity');

            $crud->display_as('conr','Komponente')
                 ->display_as('paclassnr','Bauteilklasse')
                 ->display_as('panr','Bauteil')
                 ->display_as('quantity','Anzahl');
           
            $crud->set_relation('conr','component','name');
            $crud->set_relation('panr','part','description');
            $crud->set_relation('paclassnr','partclass','name');
            $crud->set_relation_dependency('panr','paclassnr','paclassnr');
           
            $output = $crud->render();

            $this->_app_output($output);

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

My concerns are: My naming strategy for db table attributes is to use the name of the primary key beeing the same in foreign keys in other tables. Is this not applicable to grocery crud and causing the problem? Also, i set up the tables with phpMyAdmin and its seems not possible to declare a foreign key in sql, so that is missing in MariaDB table setup. Can this cause the fault?

Last not least: I thing, ajax_grocery_crud is so important to GC, you should consider to integrate it into GC and maintain it. As far as i can see, it only adds one function to GC dokumentation. My GC version is 1.6.3 and CI is 3.1.10