1

I need to have placeholders in textbox of filters in yii CGridView I followed this question but it is not working anybody has idea how to make it work?

Community
  • 1
  • 1
Dirgh
  • 507
  • 4
  • 13

2 Answers2

3

Suppose you have a code like in below of your grid view.

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'product-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'id',
        'product_name',
        'product.description',  
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

Now you want to add placeholder to product_name, then you may change it above code to ....

<?php $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'product-grid',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(
            'id',
             array('name'=>'product_name', 'filter'=>CHtml::activeTextField($model, 'product_name',array("placeholder"=>"place holder text"))),        
            'product.description',
            array(
                'class'=>'CButtonColumn',
            ),
        ),
    )); ?>

Secondly, if you want to add place holders for all columns then if you adding it in CGridView code then you should have to add separately but i think you may add it to use by CSS by adding property for that specific columns. Check the link below too. How to set placeholder value using CSS?

Hope it will help you.

Thanks

Community
  • 1
  • 1
1

Structure like below is working copy .

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'car-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'id',
        'manufacturer',
        array('name'=>'model','value'=>'$data->model',
                    'filter'=>CHtml::activeTextField($model, 'model',array("placeholder"=>"place holder text"))),
        array(
            'class'=>'CButtonColumn',
        ),
    ),
));

Please check properly, set 'filter' above and below like in this code sample .

Chaulagai
  • 752
  • 8
  • 12
  • is there any way to have same placeholder for all columns without going into details of columns – Dirgh Dec 16 '13 at 03:20