【问题标题】:Adding a Dojo Datagrid to a ZF Dojo_Form, how can I do it?将 Dojo Datagrid 添加到 ZF Dojo_Form,我该怎么做?
【发布时间】:2012-05-20 18:10:32
【问题描述】:

我有这个带有几个子表单的表单我正在使用 tabContainer,
在其中一个中,单击时我有一个按钮,希望在那个“空间”子表单中 会出现一个带有一些值的数据网格。

有没有可能,怎么做?

我尝试创建一个 datagrid View Helper,但这不能正常工作,DataGrid 没有显示。

使用的代码:

/** * DataGrid 的描述 * * @author andref * @version $Id$ */ 类 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;
}
     }

【问题讨论】:

    标签: php datagrid dojo zend-form


    【解决方案1】:

    尝试在纯js中创建一个网格并放置它 在你的元素中使用 grid.placeat("idOfElement") 。看这里:

    http://dojotoolkit.org/reference-guide/1.8/dojox/grid/DataGrid.html

    【讨论】:

      猜你喜欢
      • 2018-01-16
      • 2022-12-06
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      • 1970-01-01
      • 2014-03-31
      • 2017-12-26
      • 1970-01-01
      相关资源
      最近更新 更多