Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Gridfield column behaviour in list view


Go to End


5 Posts   3059 Views

Avatar
tmkp

Community Member, 42 Posts

5 July 2012 at 6:30am

Hi again,
is there any way yet to control column width in the gridfield list view?

Again following this example, using long text in the Description field of a contact will result in a very very wide column with all of the text in one line and no line breaks.

Also, the Main Content and Contacts tabs + the Add New button are being moved outside of the visible area to the far right of the scrolling pane.

I've already filed a ticket a couple days ago which is here, but no response so far.

Version is 3.0 stable, issue occurs with sortable grid field both active and deactivated.

Any ideas?

Thanks in advance,
Andi

Attached Files
Avatar
martimiz

Forum Moderator, 1391 Posts

6 July 2012 at 12:01am

I suppose, while there is no 'official solution' yet, you could try and use css styles to limit the width of a column. By default every colum's td gets a class 'col-fieldname' added to it.

you could try setting a CustomCSS requirement for it. Say, from within the getCMSFields() function or, in ModelAdmin, from your admin class init()...

Avatar
tmkp

Community Member, 42 Posts

6 July 2012 at 5:29am

Edited: 06/07/2012 8:46am

Just adding width rules to the columns doesn't work, as for some reason there's a "whitespace:no-wrap" rule added to every table cell by default, resulting in columns stretching endlessly.

Came up with this workaround. It's not pretty but it should do for the time being:

mysite/css/contacts-admin.css

table.ss-gridfield-table td {
	white-space:normal !important;
}

table.ss-gridfield-table td.col-Thumbnail {
	width:15% !important;
}

table.ss-gridfield-table td.col-Name {
	width:15% !important;
}

table.ss-gridfield-table td.col-Description {
	width:40% !important;
}

table.ss-gridfield-table td.col-Website {
	width:22% !important;
}

ContactListPage.php

// Create Grid Field
public function getCMSFields() {
	Requirements::css("mysite/css/contacts-admin.css");
	...
}

Now the only remaining issue is that the Description text is one single blob of text, stripped of all paragraphs/linebreaks. Custom getters again don't seem to be working on this one. I'll keep digging.

Thanks martimiz!

Avatar
jak

Community Member, 46 Posts

11 July 2012 at 9:16pm


Now the only remaining issue is that the Description text is one single blob of text, stripped of all paragraphs/linebreaks. Custom getters again don't seem to be working on this one. I'll keep digging.

This is currently broken, see http://open.silverstripe.org/ticket/7590. I posted a workaround in http://www.silverstripe.org/general-questions/show/20136

HTH
Jak

Avatar
Graphicator

Community Member, 62 Posts

14 August 2012 at 11:18am

For my purposes, I just had to comment out the white-space rule on GridField.css, but I only checked it in one browser.

I was getting a long single line that didn't wrap, and this fixed the stretched out column look.

.cms table.ss-gridfield-table tbody td {
/* white-space: nowrap; */
width: auto;
}

I'd like to know when the width is controlled soon.