⚠ 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

Is this a BUG: callback fields name is being overridden



bluepicaso

bluepicaso
  • profile picture
  • Member

Posted 04 December 2013 - 09:26 AM

So i had a category table,
thats stores both category and subcategory within that same table and had a parent field
[attachment=730:Selection_006.png]

so i had to show all child categories with names of their parent categories.
I tried using self join but it did not work.
So i did a callback to get the parent category name
here is the code.

 

/*
	 * function manageSubChannels
	 * @param: 
	 * desc:	function to manage sub channels
	 */
	
	function manageSubChannels() {
		if(isAdmin()){
			$crud = new grocery_CRUD();
      $crud->set_theme('flexigrid');
			$crud->columns('chnlName', 'chnlStatus','chnlParent');
			$crud->display_as('chnlName','Channel Name');
			$crud->display_as('chnlStatus','Is Active');
			$crud->display_as('chnlParent','Child Of');
			$crud->change_field_type('chnlStatus', 'true_false');
      $crud->set_table('ci_channel');
			$state = $crud->getState();
			if($state == 'list' || $state == 'success'){
				$crud->callback_column('chnlParent',array($this,'_getChannelParentName'));
			}
			if($state == 'add' || $state == 'edit'){
				$crud->callback_edit_field('chnlParent',array($this,'_getParentsForChannel'));
			}
			
			$crud->where('chnlParent !=', 0);
      $output = $crud->render();
      $data['logdIn'] = true;
			$data['head'] = "Manage Sub-Channels";
      $output = array_merge($data,(array)$output);
      $this->_outputData($output);
		}
		else{
			showMsg('Your session has expired', 1, base_url());
		}
	}
	
	/*
	 * function _getChannelParentName
	 * @param: $value, $row
	 * desc:	function to get channel parent name
	 */
	
	function _getChannelParentName($value, $row) {
		$parent = @$this->get->getChannelParent($row->chnlId);
		if(!empty($parent)){
			foreach($parent as $pr){
				return $pr['chnlName'];
			}
		}
	}
	
	/*
	 * function _getParentsForChannel
	 * @param: $value, $row
	 * desc:	function to get all panet channels
	 */
	
	function _getParentsForChannel($value, $row) {
		$channels = $this->get->getChannels();
		$dd='';
		if(!empty($channels)){
			$dd = '<select name="chnlParent">';
			foreach($channels as $chn){
				$dd .='<option value="'.$chn['chnlId'].'">'.$chn['chnlName'].'</option>';
			}
			$dd .= '</select>';
		}
		return $dd;
	}

the code woks fine and provides the dropdown at the time of EDIT only
but while listing it gives a problem.

When i open the listing page the names of parents are shown for 1 second and then are overridden.

checkout the video

https://www.youtube.com/watch?v=VdEWmvAflvo

 

please help me resolve this


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 05 December 2013 - 08:41 AM

Hi there,

 

this is the reason u only considering that stuff for state 'list'

if($state == 'list' || $state == 'success'){

...

But wht grocery crud also dose is it do 'ajax_list' - that too is 1 more state you need to consider for the callback.. that should solve your problem..