User Friendly Clinkcolumn

I made a ClinkColumn :


array(

			'class'=>'CLinkColumn',

			'header'=>'link to law source',

			'labelExpression'=>'link',

			'urlExpression'=>'$data->relatedlinks',

			'htmlOptions'=>array('style' => 'text-align: center;','width'=>'40px'), 

		),	

which is working well , but not quite user friendly:

  1. The blue "link" is being shown in every cell , even if it is NULL

  2. When I click on the link , the row is being selected (marked in green)

I couldn’t find the answers for these two , so does anyone have suggestions?

I’ve not used CLinkColumn, but here’s an easy way to do it with a CDataColumn:




    array(

        'type'=>'raw',

        'header'=>'link to law source',

        'htmlOptions'=>array('style' => 'text-align: center;','width'=>'40px'),

        'value'=>function($data){

            if ($data->relatedlinks === null)

                return '';


            return CHtml::link('link', $data->relatedlinks, array('class'=>'law-link'));

        },

    ),



You could add something like this to prevent the highlighting of the row (untested, so it may need tweaking):




<script type="text/javascript">

    $("body").on("click", "a.law-link", function(e){

        e.stopPropagation();

        return true;

    });

</script>



Bombora!

Thanks Keith!

Both codes are working well!

Cheers,

Mark.

Ok , a small edit:

I had to modify the line where if there is no link , the word itself won’t be showed, however , I still get it sometimes , even that in the DB that field is NULL.

Any ideas why?


'value'=>function($data){

            if ($data->relatedlinks == null or $data->relatedlinks == ' ')

                return '';										

            return CHtml::link('link', $data->relatedlinks, array('class'=>'law-link'));			

        },