Wilson Ng Wilson Ng - 1 month ago 10
jQuery Question

Get selected rows value from kartik gridView in modal and pass it to parent form

I try to get value from modal bootstrap (contain table kartik gridview), and i want to pass the selected value to parent form (action create form). How to do that? Please advice.
modal form contains fields like this

$gridColumns = [
'attribute' => 'agen_id',
'value' => 'agen.agen_name'
'attribute' => 'price',
'format' => ['decimal', 0],

] ?>

and this is the button in parent form

<div class="col-xs-8">
<div class="form-group field-poagen-price">
<?= Html::button('Price List', ['value' => Url::to('../pricelist/list'), 'class' => 'btn btn-primary', 'id' => 'BtnModalPriceList']) ?>
'header' => 'List Harga',
'id' => 'modal',
'size' => 'modal-md'
echo "<div id='modalContent'></div>";

and i register my jquery like this


I want to get the value from modal to pass to the parent in order to fill the required field.
I have searched for a few days and still have no luck.
Please advice for the master. Thanks before.


I have solved it. This is what i do. Create custom button in the gridView

    'class' => 'yii\grid\ActionColumn',
    'template' => '{select}',
    'buttons' => [
        'select' => function($url, $model, $key){
            return Html::button('Select', [
                'title' => Yii::t('yii', 'Select'),
                'aria-label' => Yii::t('yii', 'Select'),                        
                'class' => 'btn btn-primary select-row',
                'data-id' => $model->id,

and then register to jquery to process the data

$(document).on('click', '.select-row', function(){
    // get id from custom button
    var id = $(this).attr('data-id');
    $.get('../pricelist/get-price', {id : id}, function(data){            

got help from @milos-ozegovic