Dropdown list with 3 levels hierarchy

Discuss MySQL Ajax Table Editor

Dropdown list with 3 levels hierarchy

Postby limbiz » Mon Mar 22, 2010 3:50 pm

Dear Admin,
By using $userActions, I did successfully with level [Province] to [District].
But I fail to load [Commune] after [District] was changed.
Code: Select all
$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'));

$userActions = array('update_district' => array(&$this,'updateDistrict'));
$this->Editor->setConfig('userActions',$userActions);                 
--- Code here ---- how to updateCommune? -----
Please help!
limbiz
 
Posts: 25
Joined: Tue Nov 10, 2009 8:07 am

Re: Dropdown list with 3 levels hierarchy

Postby admin » Tue Mar 23, 2010 2:21 pm

You can add another entry to the user actions array.
Code: Select all
$userActions = array('update_district' => array(&$this,'updateDistrict'), 'update_commune' => array(&$this,'updateCommune'));
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Dropdown list with 3 levels hierarchy

Postby limbiz » Tue Mar 23, 2010 2:44 pm

Just tested and It's not work as expected.
By using Firebug, there is no Onchange="toAjaxTableEditor('update_commune',this.value);" in select District.
limbiz
 
Posts: 25
Joined: Tue Nov 10, 2009 8:07 am

Re: Dropdown list with 3 levels hierarchy

Postby admin » Tue Mar 23, 2010 3:03 pm

So when you change the province the district is updating correctly right?

Can you replace onchange="toAjaxTableEditor(\'update_commune\',this.value);" with a simple alert and test changing the district manually to see if the alert shows up. Also test changing the province and see if the alert shows up.
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Dropdown list with 3 levels hierarchy

Postby limbiz » Tue Mar 23, 2010 3:33 pm

yes, when changing the province the district was updating correctly.
By replacing onchange="toAjaxTableEditor(\'update_commune\',this.value);" with simple alert on district, it still not work.
But If I changed both province and district with simple alert and it worked.
limbiz
 
Posts: 25
Joined: Tue Nov 10, 2009 8:07 am

Re: Dropdown list with 3 levels hierarchy

Postby admin » Tue Mar 23, 2010 4:12 pm

Can't you just call the function to update commune in the updateDistrict() function and pass the correct district to it?
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Dropdown list with 3 levels hierarchy

Postby limbiz » Tue Mar 23, 2010 4:26 pm

I notice that, by using inspecter in firebug, when i change the province, in select tag of District there is no onchange="toAjaxTableEditor(\'update_commune\',this.value);". that's why there is no trigger on District.
limbiz
 
Posts: 25
Joined: Tue Nov 10, 2009 8:07 am

Re: Dropdown list with 3 levels hierarchy

Postby limbiz » Tue Mar 23, 2010 4:43 pm

Code: Select all
function initiateEditor()
{
   $rem_id=$_GET['_cn'];
   $action = $_GET['action'];
            
   $tableColumns['id']= array('display_text' => 'ID', 'perms' => 'VQS');
   $tableColumns['ContractNo']= array('display_text' => 'ContractNo', 'perms' => 'A','hidden_add'=>true, 'default'=>$rem_id,'data_filters' => array('filters' => array("=$rem_id")),'disable'=>true);
   $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'));
   $tableColumns['VillageID']= array('display_text' => 'Village', 'perms' => 'EVCTAXQS');   
   $tableName = 'proj_location';
   $primaryCol = 'id';
   $errorFun = array(&$this,'logError');
   $permissions = 'EAVIDU';   
   $this->Editor = new AjaxTableEditor($tableName,$primaryCol,$errorFun,$permissions,$tableColumns);
   $this->Editor->setConfig('tableInfo','cellpadding="0" cellspacing="0" width="99%" class="mateTable"');
   $this->Editor->setConfig('orderByColumn','id');
   $this->Editor->setConfig('addRowTitle',$_GET['action'].' '.$this->title);
   $this->Editor->setConfig('editRowTitle',$_GET['action'].' '.$this->title);
   //$this->Editor->setConfig('iconTitle','Edit tbl_menu');
   $this->Editor->setConfig('tableTitle',$_GET['action'].' '.$this->title);
   $this->Editor->setConfig('displayNum','10');
   
   $this->Editor->setConfig('tableScreenFun',array(&$this,'getExtraClose'));

   $userActions = array('update_district' => array(&$this,'updateDistrict'), 'update_commune' => array(&$this,'updateCommune'));
   $this->Editor->setConfig('userActions',$userActions);         
}
function updateDistrict($proId)
{
   $query = "select DistrictID,DistrictName from lutdistrict where ProvinceID = $proId";
   $result = $this->retrieve_data( $query , $mode = 'mysql_fetch_assoc' );
   $str = '<select id="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)
{
   $query = "select CommuneID,CommuneName from lutcommune where DistrictID = $disId";
   $result = $this->retrieve_data( $query , $mode = 'mysql_fetch_assoc' );
   $str = '<select id="CommuneID"><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 getExtraClose()
{
   $this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'setTimeout("insertCloseButton();",100);');
}
limbiz
 
Posts: 25
Joined: Tue Nov 10, 2009 8:07 am

Re: Dropdown list with 3 levels hierarchy

Postby admin » Tue Mar 23, 2010 11:28 pm

The new drop down that you are replacing the old one with does not have the onchange event. Try this
Code: Select all
function updateCommune($disId)
{
   $query = "select CommuneID,CommuneName from lutcommune where DistrictID = $disId";
   $result = $this->retrieve_data( $query , $mode = 'mysql_fetch_assoc' );
   $str = '<select id="CommuneID" onchange="toAjaxTableEditor(\'update_commune\',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);
}
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Dropdown list with 3 levels hierarchy

Postby limbiz » Wed Mar 24, 2010 3:53 pm

After applied that code, now I met another problem with Province. Nothing happens when i changed the province...just see only loading animation.
limbiz
 
Posts: 25
Joined: Tue Nov 10, 2009 8:07 am

Next

Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 6 guests

cron