PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] Get the value of a value in the widgets CgridView

 March 08, 2022     javascript, jquery, php, widget, yii     No comments   

Issue

Good night I'm trying to capture the id of a row cdesde a CgridView I hope they can help me any suggestions I'll be grateful, regards

Function that calls the window where the CgridView is located

<script >
 function buscarArticulo() {
 window.open("../articulo/catInventario", "popupId", "location=no,menubar=no,titlebar=no,resizable=no,toolbar=no, menubar=no,width=500,height=500"); 
 }

 </script>

This is the function in the popup window:

<script language="javascript">
function cerrar(idarticulo) {
window.opener.document.getElementById('idarticulo').value = <?php echo $model->idarticulo; //the new id ?> 
window.close();
}
</script>

This is the CgridView widget:

<?php $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'catInventario-grid',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(
                'idarticulo',
                'codigo',
                'nombre',
                'descripcion',
                'imagen',
                'uso_interno',
                /*
                'idcategoria',
                'idpresentacion',
                'cod_impuesto',
                */
                array(
                        'class'=>'CButtonColumn',
                        'template'=>'{elegir}',
                        'buttons'=>array(
                                'elegir'=>array(
                                        'click'=>'cerrar',
                                        ),

                                ),

                ),
        ),
)); ?>

This is the model, where is the search for the complete search

public function search()
        {


                $criteria=new CDbCriteria;

                $criteria->compare('idarticulo',$this->idarticulo);
                $criteria->compare('codigo',$this->codigo,true);
                $criteria->compare('nombre',$this->nombre,true);
                $criteria->compare('descripcion',$this->descripcion,true);
                $criteria->compare('imagen',$this->imagen,true);
                $criteria->compare('uso_interno',$this->uso_interno,true);
                $criteria->compare('idcategoria',$this->idcategoria);
                $criteria->compare('idpresentacion',$this->idpresentacion);
                $criteria->compare('cod_impuesto',$this->cod_impuesto,true);

                return new CActiveDataProvider($this, array(
                        'criteria'=>$criteria,
                ));
        }

And this is the controller function:

public function actionCatInventario()
        {
                $model=new Articulo('search');
                $model->unsetAttributes();  // clear any default values
                if(isset($_GET['Articulo']))
                        $model->attributes=$_GET['Articulo'];

                $this->render('catInventario',array(
                        'model'=>$model,
                ));
        }

As you realize, it is for a web expenses form and for this sense I only need the idarticle, I hope to have been clear and they can help me, thank you very much for your time


Solution

I am not sure, what exactly you need. I assume you need value of first column. If so (and if there is jQuery in your project) you can get it by this

function cerrar(idarticulo) {
    console.log($(this).parent().parent().children('td:first').text());
}

It returns value of first column of CGridView.



Answered By - venoel
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing