filterHtmlOptions - style user input in filter box

Tip:

If you want to style the content that the user enters in the CGridView’s filterbox (for example “text-align : right”) then


'filterHtmlOptions'=>array('style'=>'text-align: right'),

is NOT going to work, because it will only style the outer table cell (td), and not the inner filter-container (div) or input element:




<td style="text-align: right">

    <div class="filter-container">

        <input>

    </div>

</td>



What you can do is add a class to the outer table cell:


'filterHtmlOptions'=>array('class'=>'filterBoxRight'),

which will result in this:




<td class="filterBoxRight">

    <div class="filter-container">

        <input>

    </div>

</td>



Then use the following code to style the <input>:




$(document).on('ready', function(){

    $('.filterBoxRight').find('.filter-container').find(':input').css({

        'text-align': 'right'

    });

});



Nice tip

[color="#006400"]/* Moved to proper forum section, from General Discussion for Yii 1.1.x to Tips, Snippets and Tutorials */[/color]