title: How to add a delete button in custom table in yii
body: <p>I have a form where I use ajaxSubmitButton to add product items in a HTML table. ajaxSubmitButton helps to use ajax to add item, ajax url take the values and update the table's body <code>&lt;tr&gt;</code>, <code>&lt;td&gt;</code>. In table, I want to keep a delete button in last column in every rows. When I click the delete button, a row should be deleted. But here delete button does not work. I have checked the hardcoded HTML table and jquery in views that works.</p>
  
  <p>In this circumstance, how could I solve this issue. Please help me. I have given below the form and controller's code:</p>
  
  <p>Form:</p>
  
  <pre><code>Yii::app()-&gt;clientScript-&gt;registerScript('removecartitem', "
  $('#remove').click(function(){
  $('#cartDetails tr:first').remove();
  })
  ");
  ?&gt;
  
  &lt;div class="form-group"&gt;
      &lt;div class="col-lg-2"&gt;
      &lt;?php
      // this is the ajax submit button
      echo CHtml::ajaxSubmitButton('Add Item',Yii::app()-&gt;createUrl('admin/order/cart'),
          array(
              'type'=&gt;'POST',
              'update'=&gt;'#cartTable',
          ),
          array('class'=&gt;'btn btn-primary btn-sm',));
      ?&gt;
      &lt;/div&gt;        
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;div class="col-lg-12"&gt;
                  &lt;table id="cartDetails" class="table table-bordered sortableTable responsive-table"&gt;
  
                      &lt;tbody id="cartTable"&gt; // ajax updates this id 
                      &lt;/tbody&gt;
                  &lt;/table&gt;
  
      &lt;/div&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>In controller:</p>
  
  <pre><code>public function actionCart()
  {
      if(isset($_POST["Order"])){            
      .....
      ..... 
      $cartDetails = Yii::app()-&gt;session['cart'];
      if(!empty($cartDetails)){
          foreach($cartDetails as $cart){
              echo '&lt;tr&gt;';
              echo '&lt;td&gt;'.$cart["product_id"].'&lt;/td&gt;';
              echo '&lt;td&gt;'.$cart["product_name"].'&lt;/td&gt;';
              echo '&lt;td&gt;'.$cart["product_code"].'&lt;/td&gt;';
              echo '&lt;td&gt;'.$cart["quantity"].'&lt;/td&gt;';
              echo '&lt;td&gt;'.$cart["price"].'&lt;/td&gt;';
              echo '&lt;td&gt;'.$cart["totalPrice"].'&lt;/td&gt;';
              echo '&lt;td&gt;&lt;input type="button" name="add" id="remove" value="Remove" class="btn btn-danger btn-xs"/&gt;&lt;/td&gt;';
              echo '&lt;/tr&gt;';
  
          }
      }
  
  }
  </code></pre>
  
  <p>At this stage, none of jquery works. Please help how to enable jquery then how to activated the delete button. Please let me know if my explanation is not clear. I have added an images to explain more clear.</p>
  
  <p><img src="https://i.stack.imgur.com/bI3Mh.png" alt="enter image description here"> </p>