Remove Renderkeys From Cgridview

Hi All

I use the widget CGridView and I want to send the generated html to email sender

but the html contains

<div class="keys" title="the url" style="display:none"> that displayed in email (althought the display:none)

renderKeys in run method of CBaseListView generates this code.

How can I remove this line without tricks (preg_replace) or extending the class(es) ?

Thanks

can you post thre grid code?

i think you can pass the htmlpotions

like


'htmlOptions' => array('style'=>''),

i am not sure it’s work or not

[size=2]Unfortunately this is html tag and already has style="display:none"[/size]

so I am afraid that have to remove with preg_replace or extend and override the ‘run’ method of CBaseListView class

i think you can display the


 'value' => 'CHtml::encode($data["device_name"])',

remove the CHtml::encode


'value' => '$data["device_name"]',

can you ple post a gridcode?

[size=2]Maggie[/size]

As I described, renderKeys generates this div html element (NOT I by column-attribute)

this div used from cgridview for other purpose. (not for displaying)

So this behaviour is independent by the columns or other cgridview settings…


$this->widget('zii.widgets.grid.CGridView', array(

    'dataProvider'=>$dataProvider,

    'columns'=>array

    (

            'name'=>'create_time',

            'name'=>'authorName',

        array(

            'class'=>'CButtonColumn',

        ),

    ),

));

I think one way is visible property




'columns'=>array(

        array(

          'name'=>'columnName',

          'visible'=>false

            ),

         )

  1. second wqy

'filterHtmlOptions' => array('style' => 'display:none'),

[size=2]As I mentioned, this is not Column!! All you said referred to columns. [/size]

check Also

https://github.com/y...aseListView.php

run method in line 129 and renderKeys method in 188 gerenate always without condition the no-displayed (by css) div…

So if anyone knows or has experience with emails html and cgridview please let give us an another way to do that…

In any case thanks Maggie :)

Hi KonApaz,

I had exactly the same problem and went for the preg_replace option. If anyone needs it, here is my code:




$grid = $this->widget('bootstrap.widgets.TbGridView',

	array(

		'id'=>'events',

		... [your normal grid code here] ...

	),

	true);

		

echo preg_replace('%<div class="keys".*?</div>%s', '', $grid);



Please note the ‘true’ in the widget call to return the output( see also: http://www.yiiframework.com/doc/api/1.1/CBaseController#widget-detail)

Regards,

Rutger

[size=2]Hi Rutger[/size]

As I posted in the beginning of this Topic I try to avoid preg_match.

But I didn’t find a way to do that without it, so I implemented something like your code.

In any case thanks :)

I think because it’s hard coded in the run method in CBaseListView, there’s no way to prevent it from being displayed, other than extending CGridView and implement our own run method or replacing the html directly (eg. using preg_replace).




	public function run()

	{

		$this->registerClientScript();


		echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";


		$this->renderContent();

		$this->renderKeys();


		echo CHtml::closeTag($this->tagName);

	}



I’m just curious, why is it hard coded there? while renderContent is actually able to call renderKeys if we mention it in $this->template just like ‘{summary}\n{items}\n{pager}’.




public function renderContent()

	{

		ob_start();

		echo preg_replace_callback("/{(\w+)}/",array($this,'renderSection'),$this->template);

		ob_end_flush();

	}



[size=2]ok, the only one way without ‘preg_…something’ is overrides a lot of stauff (classes) and I wan’t to do that for this action.[/size]

May be I didn’t use the appropriate phrase “hard coded”. I mean it is better to make something directly rather than to make something and change it later (2 steps - more complex - more consuming - maybe more code) ;)

actually you just need to extend 1 class (CGridView), but of course it’s up to you to choose the best way to do it :)

You’re talking about your code or CBaseListView? Sorry if I was not clear, but my curiosity was about CBaseListView class itself. I’m wondering why they hard coded renderKeys there, while renderContent is actually able to call it if we specify it in the $template property. Never mind, not a big deal though…

Actually I have to extend the CGridView and use it

Because the CGridView has not ‘run’ method (inherits it from CBaseListView) I have to override the ‘run’ method of CBaseListView without use parent::run(), so the final code is


public function run()

	{

		$this->registerClientScript();


		echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";


		$this->renderContent();

		//do not use this... $this->renderKeys();


		echo CHtml::closeTag($this->tagName);

	}

Let me drop my personal opinion to your first and last post.

First. Most modern e-mail clients, that can handle and operate on HTML-rich e-mail content does fully (or nearly fully) support CSS styles as well. Which means, that if you see “<div class=“keys” title=“the url” style=“display:none”>” in your message, then it is not Yii or code problem, but an incorrect e-mail client configuration or maybe its core engine? I don’t know. All I know, is that, when I was using display:none or any other CSS style, all e-mail clients, that I tested does supported CSS styling and does hidden content, that was marked by me as hidden.

Last. Yes, you’re right. If you’re going to change something that is coded different in framework core, you should most certainly use class extending to own, private classes. This is most usable, reusable and follows modern development practices. So, as you correctly figured out, using preg_replace is a bad idea here.

Hi Trejder

About your first answer:

I agree with you, but this strange issue occurs to gmail! (…the other css styles works perfectly…)

I could believe the google has no modern e-mail system! In any case I override the class as should be done, now it works perfectly.

I am glad you to agree with me about the development parctices :)

It is the best and correctly way for OOP programming, I give you a vote :)

i guest you can add


.keys{

	display:none !important

}

in your css file. sorry if im wrong

Hi eotz

This article is very old and I dont remember how to achieve it,

I think by extend the CGridView

You cannot add external css style in email

Your solution works for the web appearance but not for emails :)