6

I am working on a custom list, and inside the list view i am showing the Title(linked to item with edit menu) column. currently when users click on this column they will be redirected to the item display form. now our customer is asking if we can redirect to different URL when clicking on the list items? so instead of redirecting to the item display form:-

/Lists/Projects/DispForm.aspx?ID=86

to be redirected to a sub-site that have the item ID, such as:-

/sites/86/

Thanks

EDIT here is my JS link , but it did not have any effect on the views:-

(function () {

      function registerRenderer() {
        var ctxForm = {};
        ctxForm.Templates = {};

        ctxForm.Templates = {
            Fields : {
                'LinkTitle': { //------ Change Hyperlink from LinkTitleNoMenu field
                    View : function (ctx) {
                        var url = String.format('{0}?ID={1}', "/PMO/Projects/", ctx.CurrentItem.ID);
                        return String.format('<a href="{0}" onclick="EditItem2(event, \'{0}\');return false;">{1}</a>', url, ctx.CurrentItem.Title);

                    }
                },
            }
        };
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
    }
    ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');


})();
7

Please try to use CSR.

Step 1: Create a JS file and paste below code.

(function () {

      function registerRenderer() {
        var ctxForm = {};
        ctxForm.Templates = {};

        ctxForm.Templates = {
            Fields : {
                'LinkTitle': { //------ Change Hyperlink of LinkTitle
                    View : function (ctx) {
                        var url = String.format('{0}?ID={1}', "/sites/86/Lists/testlist/EditTicket.aspx", ctx.CurrentItem.ID);
                        return String.format('<a href="{0}" onclick="EditItem2(event, \'{0}\');return false;">{1}</a>', url, ctx.CurrentItem.Title);
                    }
                },
            }
        };
        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctxForm);
    }
    ExecuteOrDelayUntilScriptLoaded(registerRenderer, 'clienttemplates.js');


})();

Step 2: GoTo web part properties of List View and add JS Link reference to this newly created js file (e.g. ~sitecollection/SiteAssets/CSRTest.js)

Step 3: Apply and Done

Please try and let me know if any query.

  • will try your appraoch, but i have a question as seems this js function will be applied on web-part basis not to the column itself ,, is this correct ? second question, how i can get the real name for the "Title (linked to item with edit menu)" ?? – john Gu Dec 20 '16 at 12:17
  • 1
    can you please check if your script is loading properly on page ? – Rohit Waghela Dec 20 '16 at 12:35
  • 1
    One more thing, please try to refer js link in this format only. "~sitecollection/YourJSfFilePath". – Rohit Waghela Dec 20 '16 at 12:41
  • 1
    Let us continue this discussion in chat. – Rohit Waghela Dec 20 '16 at 15:29
  • 1
    We can only access the ctx fields that are rendered (available in the current list view). So what you can do is, make the column/field available in the view and hide it with CSR. Please refer the link to hide the column with CSR --> sharepoint.stackexchange.com/questions/168898/… – Rohit Waghela Dec 20 '16 at 15:37
3

You can create hyperlink column and from list default view hide Title column and your newly created custom hyperlink column. It will redirect you to link which you will set.

  • So you prefer this appraoch over using client side rendering ? second question should i use the column template named "Hyperlink with formatting and constraints for publishing" OR "Hyperlink or Picture" , keeping in mind that i will be attaching the itemID inside the new url such as 'servername/.../sites/ItemID' – john Gu Dec 20 '16 at 12:13
  • hyperlink and picture will be fine. No need for any programming. Using OOTB you can achieve this. – shraddha shah Dec 20 '16 at 12:15
  • now i add a test hyperlink column,, but not sure how i can define that it should render the following url "servername/...../sites/ITEMID" ?? – john Gu Dec 20 '16 at 12:30
  • now i add a test hyperlink column,, but not sure how i can define that it should render the following url "servername/...../sites/ITEMID" ?? is there a way to define this inside the column setting ? or i will need to populate this filed when the item is created ? – john Gu Dec 20 '16 at 12:31
  • is it static link or dynamically you want to create link? – shraddha shah Dec 20 '16 at 12:35
3

You can achieve this using client side rendering in SharePoint 2013 by redefining LinkTitle field for the view.
There is an excellent article by Andrei Markeev on this. It also has an example that satisfies your requirement.

  • so it is better to use CSR over defining a hyperlink column as mentioned by other replies ? – john Gu Dec 20 '16 at 12:12
  • Client side rendering is meant to fulfill such requirements and would be the preferred approach – Vineet Desai Dec 20 '16 at 14:57
2

You have to create custom hyperlink column and it will redirect to new URL.

  • So you prefer this appraoch over using client side rendering ? second question should i use the column template named "Hyperlink with formatting and constraints for publishing" OR "Hyperlink or Picture" , keeping in mind that i will be attaching the itemID inside the new url such as 'servername/.../sites/ItemID' – john Gu Dec 20 '16 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.