cgridview wrap text that has no spaces

I was wondering if anyone had come across a solution for wrapping content in a cgridview that has no spaces. Wrapping works fine if the text coming back has spaces in it. But some of content is rather long and doesn’t contain spaces. Is there any way to wrap this or even just show only a certain length of the text until the end of the column.

I tried doing


'htmlOptions' => array('style' => 'max-width:100px'),

on the column options. This keeps the column width fine, but the text overflows to the right of the page

Thanks

Hello, you can do it via CSS:

[list=1]

[*]First, set your table “width” to something (I use generally 100% but it’s up to you)

[*]Set your table "table-layout" css property to "fixed"

[*]Set your column width to what you want

[*]Set your column "overflow-x" css property to "hidden", "auto", or "scroll"

[/list]

Thanks this worked really well. I didn’t have to add any options to the table itself. Just added this to the htmlOptions of the column


'htmlOptions' => array('style' => 'max-width:150px; overflow-x: auto')

You could also try word-wrap:break-word;

http://www.w3schools.com/cssref/css3_pr_word-wrap.asp

If all else fails, you could also do your own wrapping:


'value'=>function($data,$row){

	if(strlen($data->myField) > 15)

	{

		// Use the php wordwrap() function or 

		// your own code (preferably in a model function)

		return wordwrap($data->myField,15," ",true);

	}

	else

	{

		return $data->myField;

	}

},