脚本宝典收集整理的这篇文章主要介绍了如何在yii2中从gridview中选择数据,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP use yii\helPErs\HtML; use yii\grid\GridView; /* @VAR $this yii\web\View */ /* @var $seArchModel frontend\modules\production\models\ProductbatchSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $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' => 'yii\grid\SerialColumn'],['class' => 'yii\grid\CheckBoxColumn'],'itemid','productname','batchno:ntext',//'mfgdate',//'expdate',// 'mrp',// 'rate',['class' => 'yii\grid\ActionColumn'],],]); ?> </div>
_生产形式
<?PHP use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\web\View; /* @var $this yii\web\View */ /* @var $model frontend\modules\production\models\Production */ /* @var $form yii\widgets\ActiveForm */ ?> <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' => 'yii\grid\CheckBoxColumn',// you may configure additional properties here ],
用户可以单击复选框以选择网格的行.可以通过调用以下JavaScript来获取所选行
var keys = $('#my_gridview_id').yiiGridView('getSelectedRows');
以上是脚本宝典为你收集整理的如何在yii2中从gridview中选择数据全部内容,希望文章能够帮你解决如何在yii2中从gridview中选择数据所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。