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.

Customising the CMS /

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

Stop Gridfield row linking to edit


Go to End


3 Posts   2221 Views

Avatar
mi32dogs

Community Member, 75 Posts

4 April 2015 at 5:57pm

Hi,
Is there a way to stop the whole row in a gridfield to link to the edit page and have only the edit button link to the edit page?
i have a file link in the row and if you click on it it will open the pdf but also the edit page.

Thanks

Avatar
Johnny9

Community Member, 35 Posts

23 April 2015 at 7:19pm

Edited: 23/04/2015 9:12pm

Hi, you need to comment some lines in javascript.
You can find it here: framework/javascript/GridField.js
Find this code at line 116:

$('.ss-gridfield .ss-gridfield-item').entwine({
onclick: function(e) {
				if($(e.target).closest('.action').length) {
					this._super(e);
					return false;
				}

				var editLink = this.find('.edit-link');
				if(editLink.length) this.getGridField().showDetailView(editLink.prop('href'));
			},
			onmouseover: function() {
				if(this.find('.edit-link').length) this.css('cursor', 'pointer');
			},
			onmouseout: function() {
				this.css('cursor', 'default');
			}
		});

And change code to:
$('.ss-gridfield .ss-gridfield-item').entwine({
			/*onclick: function(e) {
				if($(e.target).closest('.action').length) {
					this._super(e);
					return false;
				}

				var editLink = this.find('.edit-link');
				if(editLink.length) this.getGridField().showDetailView(editLink.prop('href'));
			},*/
			onmouseover: function() {
				if(this.find('.edit-link').length) this.css('cursor', 'pointer');
			},
			onmouseout: function() {
				this.css('cursor', 'default');
			}
		});

Now, when you click on row, nothing will happen. Only then you click edit icon you wil be redirected to edit window.

Avatar
martimiz

Forum Moderator, 1391 Posts

13 January 2016 at 4:27am

Edited: 13/01/2016 4:27am

A bit late, but just in case someone needs this:

I needed to insert a target="_blank" custom link to a pdf file into the GridField rows, which worked well, but in the background ModelAdmin still went on to display the DetailForm. Triggered by the Johnny9 answer above, I did this:

config.yml

LeftAndMain:
  extra_requirements_javascript:
    - mymodule/javascript/myfile.js

mymodule/javascript/myfile.js

(function($){
	$.entwine('ss', function($) {
		$('.ss-gridfield  .ss-gridfield-item .showPDFLink').entwine({
			onclick: function(e) {
				e.stopPropagation();
			}
		});
	});
})(jQuery);

where showPDFLink is the class of the custom link