Dropdown list with 3 levels hierarchy

Discuss MySQL Ajax Table Editor

Re: Dropdown list with 3 levels hierarchy

Postby limbiz » Thu Mar 25, 2010 10:21 am

Problem solved!
Code: Select all
function initiateEditor()
{
   $tableColumns['ProvinceID']= array('display_text' => 'Province', 'perms' => 'EVCTAXQS', 'join' => array('table' => 'lutprovince', 'column' => 'ProvinceID', 'display_mask' => "ProvinceName", 'type' => 'left'),'req' => true, 'input_info' => 'onchange="toAjaxTableEditor(\'update_district\',this.value);"');
   $tableColumns['DistrictID']= array('display_text' => 'District', 'perms' => 'EVCTAXQS', 'join' => array('table' => 'lutdistrict', 'column' => 'DistrictID', 'display_mask' => "DistrictName", 'type' => 'left'),'req' => true, 'input_info' => 'onchange="toAjaxTableEditor(\'update_commune\',this.value);"');   
   $tableColumns['CommuneID']= array('display_text' => 'Commune', 'perms' => 'EVCTAXQS', 'join'=>array('table' => 'lutcommune', 'column' => 'CommuneID', 'display_mask' => 'CommuneName', 'type' => 'left'), 'input_info' => 'onchange="toAjaxTableEditor(\'update_village\',this.value);"');
   $tableColumns['VillageID']= array('display_text' => 'Village', 'perms' => 'EVCTAXQS', 'join'=>array('table'=>'lutvillage', 'column'=>'VillageID', 'display_mask'=>'VillageName', 'type'=>'left'));
   
   $userActions = array('update_district' => array(&$this,'updateDistrict'),
                   'update_commune' => array(&$this,'updateCommune'),
                   'update_village' => array(&$this,'updateVillage'));
   
   $this->Editor->setConfig('userActions',$userActions);
}
function updateDistrict($proId)
{
   if(!empty($proId)){
      $query = "select DistrictID,DistrictName from lutdistrict where ProvinceID = $proId";
      $result = $this->retrieve_data( $query , $mode = 'mysql_fetch_assoc' );
      $istr = "\'update_commune\'" ;
      $str = '<select id="DistrictID" onchange="toAjaxTableEditor('.istr.',this.value);" name="DistrictID"><option value="">Select One</option>';
      foreach( $result as $results )
      {
         $str.='<option value="'.$results['DistrictID'].'">'.$results['DistrictName'].'</option>';
      }
      $str.='</select>';
      $javascript = '$(\'DistrictID\').replace(\''.$str.'\');';                       
      $this->Editor->retArr[] = array('where' => 'javascript', 'value' => $javascript);      
  }
}
function updateCommune($disId)
{
   if(!empty($disId)){
      $query = "select CommuneID,CommuneName from lutcommune where DistrictID = $disId";
      $result = $this->retrieve_data( $query , $mode = 'mysql_fetch_assoc' );
      $istr = "\'update_village\'" ;
      $str = '<select id="CommuneID" name="CommuneID" onchange="toAjaxTableEditor('.$istr.',this.value);"><option value="">Select One</option>';
      foreach( $result as $results )
      {
         $str.='<option value="'.$results['CommuneID'].'">'.$results['CommuneName'].'</option>';
      }
      $str.='</select>';
      $javascript = '$(\'CommuneID\').replace(\''.$str.'\');';
      $this->Editor->retArr[] = array('where' => 'javascript', 'value' => $javascript);
   }
}
function updateVillage($comId)
{
   if(!empty($comId)){
      $query = "select VillageID,VillageName from lutvillage where CommuneID = $comId";
      $result = $this->retrieve_data( $query , $mode = 'mysql_fetch_assoc' );
      $str = '<select id="VillageID" name="VillageID"><option value="" >Select One</option>';
      foreach( $result as $results )
      {
         $str.='<option value="'.$results['VillageID'].'">'.$results['VillageName'].'</option>';
      }
      $str.='</select>';

      $javascript = '$(\'VillageID\').replace(\''.$str.'\');';
      $this->Editor->retArr[] = array('where' => 'javascript', 'value' => $javascript);
   }
}

I just added:
$istr = "\'update_commune\'" ;
$str = '<select id="DistrictID" onchange="toAjaxTableEditor('.istr.',this.value);" name="DistrictID"><option value="">Select One</option>';

One more thing, How could I set the width of table screen in Edit or View mode?
limbiz
 
Posts: 25
Joined: Tue Nov 10, 2009 8:07 am

Re: Dropdown list with 3 levels hierarchy

Postby admin » Thu Mar 25, 2010 1:34 pm

Good I'm glad you were able to work this out. To set the width of the tables on add or edit you need to set the view table info and edit table info config options.
Code: Select all
$this->Editor->setConfig('viewTableInfo','class="mateTable" width="400"');
$this->Editor->setConfig('editTableInfo','class="mateTable" width="400"');
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Dropdown list with 3 levels hierarchy

Postby limbiz » Thu Mar 25, 2010 1:52 pm

thanks Admin! Now seem everything in my control! lolzzz
limbiz
 
Posts: 25
Joined: Tue Nov 10, 2009 8:07 am

Re: Dropdown list with 3 levels hierarchy

Postby jltolkien » Tue Mar 08, 2011 11:39 am

Hi,
I am trying to implement something similar but only with 2 levels of hierarchy (Provincia, Comarca y Localidad).

I tried to use your code but failed. Can you help me find the error? The code is written in the main form (Lugar). See attached file for details.

Code: Select all
$tableColumns['Provincia']= array('display_text' => 'Provincia', 'perms' => 'EVCTAXQS', 'join' => array('table' => 'Provincias', 'column' => 'IDProv', 'display_mask' => "Provincias.Provincia", 'type' => 'left'), 'input_info' => 'onchange="toAjaxTableEditor(\'update_commune\',this.value);"');   
   $tableColumns['Comarca']= array('display_text' => 'Comarca', 'perms' => 'EVCTAXQS', 'join'=>array('table' => 'Comarcas', 'column' => 'IDCom', 'display_mask' => 'Comarcas.Comarca', 'type' => 'left'), 'input_info' => 'onchange="toAjaxTableEditor(\'update_village\',this.value);"');
   $tableColumns['Localidad']= array('display_text' => 'Localidad', 'perms' => 'EVCTAXQS', 'join'=>array('table'=>'Localidades', 'column'=>'IDLocalidad', 'display_mask'=>'Localidades.Localidad', 'type'=>'left'));


and

Code: Select all
function updateCommune($disId)
{
   if(!empty($disId)){
      $query = "select IDCom, Comarca from Comarcas where IDProvincia = $disId";
      $result = $this->retrieve_data( $query , $mode = 'mysql_fetch_assoc' );
      $istr = "\'update_village\'" ;
      $str = '<select id="IDCom" name="IDCom" onchange="toAjaxTableEditor('.$istr.',this.value);"><option value="">Select One</option>';
      foreach( $result as $results )
      {
         $str.='<option value="'.$results['IDCom'].'">'.$results['Comarca'].'</option>';
      }
      $str.='</select>';
      $javascript = '$(\'CommuneID\').replace(\''.$str.'\');';
      $this->Editor->retArr[] = array('where' => 'javascript', 'value' => $javascript);
   }
}

function updateVillage($comId)
{
   if(!empty($comId)){
      $query = "select IDLocalidad, Localidad from Localidades where IDComarca = $comId";
      $result = $this->retrieve_data( $query , $mode = 'mysql_fetch_assoc' );
      $str = '<select id="IDLocalidad" name="IDLocalidad"><option value="" >Select One</option>';
      foreach( $result as $results )
      {
         $str.='<option value="'.$results['IDLocalidad'].'">'.$results['Localidad'].'</option>';
      }
      $str.='</select>';

      $javascript = '$(\'VillageID\').replace(\''.$str.'\');';
      $this->Editor->retArr[] = array('where' => 'javascript', 'value' => $javascript);
   }
}


The tables are designed as follows:
(see attached file)

Thanks in advance :roll:
Attachments
ds.png
ds.png (35.33 KiB) Viewed 10829 times
jltolkien
 
Posts: 13
Joined: Tue Mar 01, 2011 1:13 pm

Re: Dropdown list with 3 levels hierarchy

Postby jltolkien » Fri Mar 11, 2011 4:00 pm

Nobody have a clue? I'm still with this issue :cry:
jltolkien
 
Posts: 13
Joined: Tue Mar 01, 2011 1:13 pm

Re: Dropdown list with 3 levels hierarchy

Postby scottdia » Mon May 15, 2017 8:49 pm

I've been trying to implement this code, and am also having issues:
Here is my code:

$tableColumns['cat_idfk'] = array(
'col_header_info' => 'max-width="50" style="white-space: normal;"',

'display_text' => 'Main Category',
'perms' => 'EVCAXTQSFHO',
'join' => array(
'table' => 'categories',
'column' => 'cat_id',
'display_mask' => "concat(cat_name,'<br>','(',cat_permalink,')')",
'type' => 'left',
),
'req' => true,
'input_info' => 'onchange="'.$this->mateInstances[0].'.toAjaxTableEditor(\'update_subcategory\',$(this).val());"

);

$tableColumns['subcat_idfk'] = array(
'col_header_info' => 'max-width="50" style="white-space: normal;"',

'display_text' => 'Sub-Category',
'perms' => 'EVCAXTQSFHO',
'join' => array(
'table' => 'sub_categories',
'column' => 'subcat_id',
'display_mask' => "concat(subcat_name,'<br>',subcat_permalink)",

'type' => 'left',
),

);

public function updateSubcategory($catId,$instanceName)
{
if(!empty($catId)){
$query = "select subcat_id, subcat_name from sub_categories where cat_idfk = :catId";
$queryParams = array('catId' => $catId);
$result = $this->Editor->doQuery($query,$queryParams);
$istr = "\'update_sub_subcategory\'" ;
$str = '<select id="subcat_idfk" name="subcat_idfk"><option value="">Select One</option>';
foreach( $result as $results )
{
$str.='<option value="'.$results['subcat_id'].'">'.$results['subcat_name'].'</option>';
}
$str.='</select>';
$javascript = '$(\'subcat_idfk\').replace(\''.$str.'\');';
$this->Editor->retArr[] = array('where' => 'javascript', 'value' => $javascript);

}
}


When I select the dropdown menu for Category, it should populate the Subcategory column with related values. Here is the popup that keeps appearing:
$('subcat_idfk').replace('<select id="subcat_idfk" name="subcat_idfk"><option value="">Select One</option><option value="1">Expansion Anchors</option><option value="2">Screw Anchors</option><option value="3">Undercut Anchors</option><option value="4">Nail Anchors</option><option value="5">Impact Anchors</option><option value="6">Bolt & Shield Anchors</option><option value="7">Rod Hanging Systems</option><option value="8">Pin Anchors</option><option value="20">Hangermate®+ Anchors</option><option value="21">Cast In Place Anchors</option></select>'); did not execute correctly. Error: TypeError: $('subcat_idfk').replace is not a function. (In '$('subcat_idfk').replace', '$('subcat_idfk').replace' is undefined)

So it looks like the values are properly appearing, but there is some issue with the javascript.
scottdia
 
Posts: 7
Joined: Wed Sep 07, 2016 8:01 pm

Previous

Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 6 guests

cron