Jump to content


Is this a BUG: callback fields name is being overridden

override callback field self join

  • Please log in to reply
1 reply to this topic

#1 bluepicaso

bluepicaso

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationIndia

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

 

please help me resolve this


Harpreet Singh Bhatia
[web developer, programmer, entrepreneur]
Portfolio: TheCodingBox


Follow Me: facebook.png twitter.png googleplus.pngskype.png


#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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







Also tagged with one or more of these keywords: override, callback, field, self, join

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users