0
votes

I am using GridView to list data in my application but today i realized that i need dynamicalli add/remove rows to/from this list. I found some javascript to do this but this is not very elegant. I googled for an extension or module like Karje's GridView extension but ther aren't that much. What do you use for this kind of task or what do you think what is the most simpliest way to make this?

I tried unclead/yii2-multiple-input package. It is so great but instead of ActiveForm I need to use Html::dopDownList elements. Is it a way somehow to use with it?

<tbody>
      <?= $form->field($megrendelt_r, 'termek_id')->widget(\unclead\widgets\MultipleInput::className(), [
           'limit' => 6,
      ]) ?>
      </tbody>

Thank you for your answers!

1
Can you please share your code what you have try so far? - Denis Bhojvani
Just updated the post with some more detail. Actually I found a great package. (Shown in the op) - Gabesz
You want to add a row or a column? - Muhammad Shahzad
Just a row. Actually it works fine but i don't want to use ActiveForm. Now I am trying with pure Javascript to make it. - Gabesz

1 Answers

1
votes

Using jQuery

    $(document).ready(function(e) {
       var $table = $('#gridViewId table tbody'); //gridViewId = your grid view 'id'

       var $rows = $table.find('tr');
       var rowNum = $rows.size(); 
       var columnsNum = $($rows[0]).find('td').size(); 

       for(var i = 0; i < rowNum; i++) {
           var $row = $($rows[i]);

           //add a row after
           $($row).after('<tr><td colspan='+ columnsNum +'>Lore Ipsum</td></tr>');
       }       
    });