简体   繁体   English

动态添加和删除表行-Yii Framework

[英]Dynamically adding and deleting table rows - Yii Framework

I am trying to create form by dynamically adding rows and deleting it when user clicks on delete button using php code, 我正在尝试通过动态添加行并在用户使用php代码单击删除按钮时将其删除来创建表单,

在此处输入图片说明

below is my code to render first row while opening the form , 下面是我在打开表单时呈现第一行的代码,

<div class="selector-details" style="display:none">
    <div class='newfield'>
      <div id='container'>  
      <table id="tid">
       <tr>
        <td><?php echo CHtml::dropDownList('field_list','',$field_name); ?></td>
       <td><?php echo CHtml::dropDownList('field_list','',$operator); ?></td>
       <td><?php echo CHtml::textField('querybox'); ?></td>
       <td> <?php echo CHtml::imageButton(Yii::app()->request->baseUrl.'/images/Trash.jpg',array('class'=>'trash-action')); ?></td>
       <?php echo "<br>"; ?>
        <td> <?php echo CHtml::dropDownList('condition_check','',$condition_check);?></td>
        </tr>

      </table>

    </div>
    </div>
    <?php 
    echo CHtml::button('Add',array('class'=>'addfield-button','background-style'=>'none'));

how i should make call the above code to add rows and delete particular row when user clicks on the row delete button ? 当用户单击行删除按钮时,我应该如何调用上面的代码来添加行和删除特定行? I am new to yii please provide any idea to go further. 我是yii的新手,请提供进一步的想法。

        $script = 'alert("hello")';
        Yii::app()->getClientScript()->registerScript('#test', $script,CClientScript::POS_HEAD  );
        echo CHtml::button('Add',array('class'=>'addfield-button','background-style'=>'none','onclick'=>$script));

if you real want to use Yii style, you can open framework code and there is a good code that you want, search : CButtonColumn.php 如果您确实想使用Yii样式,则可以打开框架代码,并找到一个不错的代码,请搜索:CButtonColumn.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM