加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何在yii2中从gridview中选择数据

发布时间:2020-12-13 17:00:18 所属栏目:PHP教程 来源:网络整理
导读:我必须将数据插入“生产”表. productid,productname,batchno存储在表’productbatch’中.我想在gridview上单击gridview时从gridview中选择这些字段.我怎样才能做到这一点? producbatch的index.php – ?phpuse yiihelpersHtml;use yiigridGridView;/* @
我必须将数据插入“生产”表. productid,productname,batchno存储在表’productbatch’中.我想在gridview上单击gridview时从gridview中选择这些字段.我怎样才能做到这一点?
producbatch的index.php –

<?php

use yiihelpersHtml;
use yiigridGridView;

/* @var $this yiiwebView */
/* @var $searchModel frontendmodulesproductionmodelsProductbatchSearch */
/* @var $dataProvider yiidataActiveDataProvider */

$this->title = 'Productbatches';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="productbatch-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search',['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create Productbatch',['create'],['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,'filterModel' => $searchModel,'columns' => [
            //['class' => 'yiigridSerialColumn'],['class' => 'yiigridCheckboxColumn'],'itemid','productname','batchno:ntext',//'mfgdate',//'expdate',// 'mrp',// 'rate',['class' => 'yiigridActionColumn'],],]); ?>

</div>

_生产形式

<?php

use yiihelpersHtml;
use yiiwidgetsActiveForm;
use yiiwebView;
/* @var $this yiiwebView */
/* @var $model frontendmodulesproductionmodelsProduction */
/* @var $form yiiwidgetsActiveForm */
?>

<div class="production-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model,'productiondate')->textInput() ?>

    <?= $form->field($model,'itemid')->textInput() ?>

    <?= $form->field($model,'productname')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model,'batchno')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model,'prodqty')->textInput() ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update',['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
<?php
    $this->RegisterJs ( "
    $('document').ready(function(){
        // $('#".Html::getInputId($model,'mrp')."').keyup(function(){ 
        //              var total = this.value;
        //              var percent = 10;
        //              var discount_value = this.value - ((total / 100) * percent);
        //             $('#".Html::getInputId($model,'rate')."').val(discount_value);    
        //          });
         var keys = $('#grid').yiiGridView('getSelectedRows');
    });

    ",View::POS_END);
  ?>

解决方法

最简单的方法是基于检查列并获取数组中的重新排列的行

这是来自yii指南http://www.yiiframework.com/doc-2.0/guide-output-data-widgets.html#checkbox-column

echo GridView::widget([
        'dataProvider' => $dataProvider,'id' => 'my_gridview_id','columns' => [
            // ...
        [
            'class' => 'yiigridCheckboxColumn',// you may configure additional properties here
        ],

用户可以单击复选框以选择网格的行.可以通过调用以下JavaScript来获取所选行

var keys = $('#my_gridview_id').yiiGridView('getSelectedRows');

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读