Php 将Dojo数据网格添加到ZF Dojo_表单中,我该如何做?
我有一个带有多个子表单的表单,我正在使用一个tabContainer,Php 将Dojo数据网格添加到ZF Dojo_表单中,我该如何做?,php,datagrid,dojo,zend-form,Php,Datagrid,Dojo,Zend Form,我有一个带有多个子表单的表单,我正在使用一个tabContainer, 在其中一个窗口中,单击时我有一个按钮,希望它位于“空间”子窗体中 数据网格将显示一些值 有可能做到这一点吗?如何做到 我尝试创建一个datagrid视图帮助器,但没有正常工作datagrid没有显示 使用的代码: /***DataGrid**@author andref*@version$Id$ */类Zend\u View\u Helper\u DataGrid{ private$_nameDG='DefaultSt' p
在其中一个窗口中,单击时我有一个按钮,希望它位于“空间”子窗体中 数据网格将显示一些值 有可能做到这一点吗?如何做到 我尝试创建一个datagrid视图帮助器,但没有正常工作datagrid没有显示 使用的代码: /***DataGrid**@author andref*@version$Id$ */类Zend\u View\u Helper\u DataGrid{ private$_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;
}
}
private$\u action='';
私有$密钥=“”;
private$\u selectMode=“single”;
私有$_字段=数组();
私有$_存储='getall/';
公共函数dataGrid($key、$action=null、$options=array())
{
如果(计数($选项)>0){
如果(数组\键\存在(“选择模式,$options)){
$this->_selectMode=$options['selectMode'];
}elseif(数组\键\存在(“字段”、$options)){
如果(!is_数组($options['fields'])){
抛出新异常(“字段不是数组”);
}
$this->_fields=$options['fields'];
}elseif(数组\键\存在(“选择模式”,$options)){
$this->_selectMode=$options['selectMode'];
}elseif(数组\键\存在(“存储”、$options)){
$this->_storage=$options['storage'];
}
}
如果($action!==null){
$this->_action=$action;
}
如果($key==null){
抛出新异常(“键不能为null”);
}
$this->_key=$key;
返回$this->_init();
}
私有函数_init()
{
$str='';
如果(!empty($this->_action)){
$str.=$this->addJS();
}
$str.=$this->storageType();
$str.=$this->draw();
返回$str;
}
/**
*返回指向窗体的双击处理程序
*
*@返回字符串
*/
公共函数addJS()
{
$str=“\n”;
$str.=“函数选取(事件)\n”;
$str.=“{\n”;
$str.=“grid=dijit.byId('grid.$this->_key.”);\n”;
$str.=“选定的\u索引=grid.focus.rowIndex;\n”;
$str.=“选定的项目=网格.getItem(选定的索引);\n”;
//不确定这是否是最有效的方法,但它对我有效
$str.=“selected\u id=grid.store.getValue(selected\u项,\”“.$this->\u键,\”“”;\n”;
$str.=“location.href=”.$this->\u action.+selected\u id;\n”;
$str.=“}\n”;
$str.=“\n”;
返回$str;
}
公共函数storageType()
{
if(strpos($this->_存储,“[”)!==false){
$st=“jsonData”。$this->\u key。“=”$this->\u存储。“\n”;
$st.=“\U键。”\”
数据=\“jsonData”。$this->\u key.\“id=\“store”。$this->\u key.\“/>”;
}否则{
$st='';
}
返回$st;
}
公共职能部门
{
$str='';
$str.=“\u键。”\“jsid=\“gridJ”。$this->\u键。”\”
query=\“{”。$this->\u key.:“*”}\“store=\“jsonStore”。$this->\u key.\”
selectionMode=\''.$this->\u selectMode.\“autoWidth=\“true”
样式=\“宽度:100%;高度:400px\”onRowDblClick='pickit();'>\n”;
$str.=“\n”;
$str.=“\n”;
foreach($this->\字段为$k=>$v){
$str.=“\t$v\n”;
}
$str.=“\n”;;
$str.=“\n”;
$str.=“\n”;
返回$str;
}
}
尝试在纯js中创建网格并放置它 在元素中使用grid.placeat(“idOfElement”)。请看这里: