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
