所属分类: 深入理解Magento Magento后台表单添加层级表格
2015-08-18 09:57
585 查看
第一步:
在后台表单中添加如下代码
$officehours_field = $fieldset->addField('rules', 'text', array(
'name' => 'rules',
'label' => Mage::helper('ditui')->__('规则区间'),
'required' => false,
));
$office_hours = $form->getElement('rules');
$office_hours->setRenderer(
$this->getLayout()->createBlock('ditui/adminhtml_rebate_edit_renderer_rules')
);
简单来描述一下以上代码的意思
在后台表单中新增一个name为rules 表单元素,接着用
ditui/adminhtml_rebate_edit_renderer_rules 类对这个表单元素的输出进行重写
第二步:创建rules文件
内容如下
Construct方法中指定输出phtml文件相对路径
Render 用来输出html
第三步:创建模板文件
<?php
$_htmlId = $this->getElement()->getHtmlId();
$_htmlClass = $this->getElement()->getClass();
$_htmlName = $this->getElement()->getName();
$_readonly = $this->getElement()->getReadonly();
$collection = Mage::registry('rebate_rule_data');
$_counter = 0;
?>
<tr>
<td class="label"><?php echo $this->getElement()->getLabel() ?></td>
<td colspan="10" class="grid hours">
<table id="attribute-options-table" class="dynamic-grid rkstorelocator-officehours" cellspacing="0" cellpadding="0"><tbody>
<tr>
<th><?php echo $this->__('销售数量(台)') ?></th><th><?php echo $this->__('推荐人单台返利(%) ') ?></th><th><?php echo $this->__('购买人单台折扣(%) ') ?></th>
<th><button id="add_new_option_button" title="Add Option" type="button" class="scalable add"><span><span><span><?php echo $this->__('Add Option') ?></span></span></span></button></th>
</tr>
<?php if(count($collection)>=1){?>
<?php foreach ($collection as $_item): ?>
<tr class="option-row rkstorelocator-officehours-dayrow" id="hour-row-<?php echo $_counter?>">
<td><input name="<?php echo $_htmlName; ?>[value][option_<?php echo $_counter ?>][num]" value="<?php echo $_item->getNum() ?
4000
>" class="input-text" type="text"></td>
<td><input name="<?php echo $_htmlName; ?>[value][option_<?php echo $_counter ?>][recommend]" value="<?php echo $_item->getRecommend() ?>" class="input-text" type="text"></td>
<td><input name="<?php echo $_htmlName; ?>[value][option_<?php echo $_counter ?>][buyer]" value="<?php echo $_item->getBuyer() ?>" class="input-text" type="text"></td>
<td class="a-left" id="delete_button_container_option_<?php echo $_counter ?>'">
<input name="<?php echo $_htmlName; ?>[value][option_<?php echo $_counter ?>][id]" value="<?php echo $_item->getId() ?>" type="hidden">
<input id="delete-row-<?php echo $_counter ?>" type="hidden" class="delete-flag" name="<?php echo $_htmlName; ?>[delete][option_<?php echo $_counter ?>]" value=""/>
<button onclick="$('hour-row-<?php echo $_counter ?>').style.display='none'; $('delete-row-<?php echo $_counter ?>').setValue(1);" title="Delete" type="button" class="scalable delete delete-option"><span><span><span>Delete</span></span></span></button>
</td>
</tr>
<?php
$_counter++;
endforeach;
}
?>
</tbody></table>
<script type="text/javascript">//<![CDATA[
var _form_html_row = '<tr class="option-row rkstorelocator-officehours-dayrow" id="hour-row-{{id}}"><td><input name="<?php echo $_htmlName; ?>[value][option_{{id}}][num]" value="" type="text"></td><td><input name="<?php echo $_htmlName; ?>[value][option_{{id}}][recommend]" value="" type="text"></td><td><input name="<?php echo $_htmlName; ?>[value][option_{{id}}][buyer]" value="" type="text"></td><td id="delete_button_container_option_{{id}}"><input name="<?php echo $_htmlName; ?>[value][option_{{id}}][id]" value="" type="hidden"><input id="delete-row-{{id}}" type="hidden" name="<?php echo $_htmlName; ?>[delete][option_{{id}}]" value=""/><button onclick="$(\'hour-row-{{id}}\').style.display=\'none\'; $(\'delete-row-{{id}}\').setValue(1);" title="Delete" type="button" class="scalable delete delete-option"><span><span><span>Delete</span></span></span></button></td></tr>';
var _rkstorelocator_counter = <?php echo $_counter?>;
$('add_new_option_button').observe('click', function(){
$('attribute-options-table').insert(_form_html_row.replace(/\{\{id\}\}/ig, _rkstorelocator_counter));
_rkstorelocator_counter++;
});
//]]></script>
</td>
</tr>以上就是对Magento 后台开发表单添加层级表格的关键代码,更多Magento开发与服务,请查看Magento
开发
在后台表单中添加如下代码
$officehours_field = $fieldset->addField('rules', 'text', array(
'name' => 'rules',
'label' => Mage::helper('ditui')->__('规则区间'),
'required' => false,
));
$office_hours = $form->getElement('rules');
$office_hours->setRenderer(
$this->getLayout()->createBlock('ditui/adminhtml_rebate_edit_renderer_rules')
);
简单来描述一下以上代码的意思
在后台表单中新增一个name为rules 表单元素,接着用
ditui/adminhtml_rebate_edit_renderer_rules 类对这个表单元素的输出进行重写
第二步:创建rules文件
内容如下
class Ares_Ditui_Block_Adminhtml_Rebate_Edit_Renderer_Rules extends Mage_Adminhtml_Block_Widget implements Varien_Data_Form_Element_Renderer_Interface { /** * Initialize block */ public function __construct() { $this->setTemplate('ditui/rebate/edit/renderer/rules.phtml'); } /** * Render HTML * * @param Varien_Data_Form_Element_Abstract $element * @return string */ public function render(Varien_Data_Form_Element_Abstract $element) { $this->setElement($element); return $this->toHtml(); } }
Construct方法中指定输出phtml文件相对路径
Render 用来输出html
第三步:创建模板文件
<?php
$_htmlId = $this->getElement()->getHtmlId();
$_htmlClass = $this->getElement()->getClass();
$_htmlName = $this->getElement()->getName();
$_readonly = $this->getElement()->getReadonly();
$collection = Mage::registry('rebate_rule_data');
$_counter = 0;
?>
<tr>
<td class="label"><?php echo $this->getElement()->getLabel() ?></td>
<td colspan="10" class="grid hours">
<table id="attribute-options-table" class="dynamic-grid rkstorelocator-officehours" cellspacing="0" cellpadding="0"><tbody>
<tr>
<th><?php echo $this->__('销售数量(台)') ?></th><th><?php echo $this->__('推荐人单台返利(%) ') ?></th><th><?php echo $this->__('购买人单台折扣(%) ') ?></th>
<th><button id="add_new_option_button" title="Add Option" type="button" class="scalable add"><span><span><span><?php echo $this->__('Add Option') ?></span></span></span></button></th>
</tr>
<?php if(count($collection)>=1){?>
<?php foreach ($collection as $_item): ?>
<tr class="option-row rkstorelocator-officehours-dayrow" id="hour-row-<?php echo $_counter?>">
<td><input name="<?php echo $_htmlName; ?>[value][option_<?php echo $_counter ?>][num]" value="<?php echo $_item->getNum() ?
4000
>" class="input-text" type="text"></td>
<td><input name="<?php echo $_htmlName; ?>[value][option_<?php echo $_counter ?>][recommend]" value="<?php echo $_item->getRecommend() ?>" class="input-text" type="text"></td>
<td><input name="<?php echo $_htmlName; ?>[value][option_<?php echo $_counter ?>][buyer]" value="<?php echo $_item->getBuyer() ?>" class="input-text" type="text"></td>
<td class="a-left" id="delete_button_container_option_<?php echo $_counter ?>'">
<input name="<?php echo $_htmlName; ?>[value][option_<?php echo $_counter ?>][id]" value="<?php echo $_item->getId() ?>" type="hidden">
<input id="delete-row-<?php echo $_counter ?>" type="hidden" class="delete-flag" name="<?php echo $_htmlName; ?>[delete][option_<?php echo $_counter ?>]" value=""/>
<button onclick="$('hour-row-<?php echo $_counter ?>').style.display='none'; $('delete-row-<?php echo $_counter ?>').setValue(1);" title="Delete" type="button" class="scalable delete delete-option"><span><span><span>Delete</span></span></span></button>
</td>
</tr>
<?php
$_counter++;
endforeach;
}
?>
</tbody></table>
<script type="text/javascript">//<![CDATA[
var _form_html_row = '<tr class="option-row rkstorelocator-officehours-dayrow" id="hour-row-{{id}}"><td><input name="<?php echo $_htmlName; ?>[value][option_{{id}}][num]" value="" type="text"></td><td><input name="<?php echo $_htmlName; ?>[value][option_{{id}}][recommend]" value="" type="text"></td><td><input name="<?php echo $_htmlName; ?>[value][option_{{id}}][buyer]" value="" type="text"></td><td id="delete_button_container_option_{{id}}"><input name="<?php echo $_htmlName; ?>[value][option_{{id}}][id]" value="" type="hidden"><input id="delete-row-{{id}}" type="hidden" name="<?php echo $_htmlName; ?>[delete][option_{{id}}]" value=""/><button onclick="$(\'hour-row-{{id}}\').style.display=\'none\'; $(\'delete-row-{{id}}\').setValue(1);" title="Delete" type="button" class="scalable delete delete-option"><span><span><span>Delete</span></span></span></button></td></tr>';
var _rkstorelocator_counter = <?php echo $_counter?>;
$('add_new_option_button').observe('click', function(){
$('attribute-options-table').insert(_form_html_row.replace(/\{\{id\}\}/ig, _rkstorelocator_counter));
_rkstorelocator_counter++;
});
//]]></script>
</td>
</tr>以上就是对Magento 后台开发表单添加层级表格的关键代码,更多Magento开发与服务,请查看Magento
开发
相关文章推荐
- Magento开发的深入
- 混合商业模式解决方案-----多种电子商务模式的融合与创新
- Magento — B2C与B2B平台
- B2B电子商务解决方案 — B2B的B2C化
- 社会化电子商务解决方案 — 社会化电子商务带来的新机遇
- MEC电子商务 — 利用全球最先进的开源软件为您的商业需求服务
- MEC电子商务 — 电子商务供应链解决方案
- 移动电子商务 — 重新拉近与消费者的距离
- 全球电子商务解决方案 — 全球电子商务的商机与挑战
- B2C电子商务解决方案 — 让客户行为述说潜在商机
- div三列,左右固定宽度,中间自适应
- 正则表达式30分钟入门教程
- java-web-j2e学习建议路线
- 不做播放器改玩社交 网络音乐又捞到救命稻草了?
- (C/C++学习笔记)函数模板加强
- 基于Jquery的原生态dialog弹出窗口-zapWindow
- HDU 1541 Stars(树状数组)
- 1037. Magic Coupon
- char*数组(c类型字符串)和c++中的string的转换、字符串比较、char*数组等问题
- LeetCode:Path Sum