2012-05-12 20 views
0

我有這種形式與幾個subForms我使用一個tabContainer,
在其中之一,我有一個按鈕,當點擊想要在那個「空間」subForm 一個數據網格會出現一些值。將Dojo Datagrid添加到ZF Dojo_Form中,我該怎麼做?

是否有可能這樣做,怎麼樣?

我試着創建一個datagrid視圖助手,但這沒有正常工作DataGrid不顯示。

代碼用於:

/** *數據網格的描述* * @author andref * @version $ $編號* /類Zend_View_Helper_DataGrid { 私人$ _nameDG = 'DefaultSt';

private $_action  = ''; 

private $_key  = ''; 

private $_selectMode = "single"; 

private $_fields  = array(); 

private $_storage = 'getall/'; 

public function dataGrid($key, $action = null, $options = array()) 
{ 

    if (count($options) > 0) { 
     if (array_key_exists("selectmode", $options)) { 
      $this->_selectMode = $options['selectmode']; 
     } elseif (array_key_exists("fields", $options)) { 
      if (!is_array($options['fields'])) { 
       throw new Exception("fields is not an array"); 
      } 
      $this->_fields = $options['fields']; 
     } elseif(array_key_exists("selectmode", $options)) { 
      $this->_selectMode = $options['selectmode']; 
     } elseif(array_key_exists("storage", $options)) { 
       $this->_storage = $options['storage']; 
     } 
    } 

    if ($action !== null) { 
     $this->_action = $action; 
    } 

    if ($key === null) { 
     throw new Exception("Key cannot be null."); 
    } 

    $this->_key = $key; 

    return $this->_init(); 
} 

private function _init() 
{ 
    $str = ''; 
    if (!empty($this->_action)) { 
     $str .= $this->addJS(); 
    } 

    $str .= $this->storageType(); 

    $str .= $this->draw(); 

    return $str; 
} 
/** 
* Returns double click handler to direct to a form 
* 
* @return String 
*/ 
public function addJS() 
{ 
    $str = "<script type=\"text/Javascript\">\n"; 
    $str .= "function pickit(event)\n"; 
    $str .= "{\n"; 
    $str .= "grid = dijit.byId('grid".$this->_key."');\n"; 
    $str .= "selected_index = grid.focus.rowIndex;\n"; 
    $str .= "selected_item = grid.getItem(selected_index);\n"; 
    //Not sure if this is the most efficient way but it worked for me 
    $str .= "selected_id = grid.store.getValue(selected_item, \"".$this->_key."\");\n"; 
    $str .= "location.href = " . $this->_action . "+selected_id;\n"; 
    $str .= "}\n"; 
    $str .= "</script>\n"; 

    return $str; 
} 

public function storageType() 
{ 
    if (strpos($this->_storage, "[") !== false) { 
     $st = "jsonData".$this->_key . " = " . $this->_storage."\n"; 
     $st .= "<gett dojoType=\"dojo.data.ItemFileReadStore\" 
      jsId=\"jsonStore" . $this->_key . "\" 
       data=\"jsonData" . $this->_key . "\" id=\"store" . $this->_key . "\" />"; 
    } else { 
     $st = '<gett dojoType="dojo.data.ItemFileReadStore" jsId=\"jsonStore'.$this->_key.'" 
    url="' . $this->_storage . '" id="store'.$this->_key.'" />'; 
    } 

    return $st; 
} 

public function draw() 
{ 
    $str = ''; 
    $str .= "<table dojoType=\"dojox.grid.DataGrid\" id=\"grid".$this->_key."\" jsid=\"gridJ".$this->_key."\" 
    query=\"{ " . $this->_key . ": '*' }\" store=\"jsonStore".$this->_key."\" 
    selectionMode=\"" . $this->_selectMode . "\" autoWidth=\"true\" 
    style=\"width: 100%; height: 400px\" onRowDblClick='pickit();'>\n"; 
    $str .= "<thead>\n"; 
    $str .= "<tr>\n"; 
    foreach ($this->_fields as $k => $v) { 
     $str .= "\t<th field=\"$k\">$v</th>\n"; 
    } 
    $str .= "</tr>\n";; 
    $str .= "</thead>\n"; 
    $str .= "</table>\n"; 

    return $str; 
} 
    } 

回答