0

Here is the code I'm using. Keep in mind that I know practically nothing about javascript and borrowed the code from someone else. He hasn't had time to look at it yet. I'm just trying to modify it to open each list item in a modal dialog. This is SharePoint 2010.

<div id="ExternalListContainer"></div>
<script type="text/javascript">
  //wait for SP to load up
  ExecuteOrDelayUntilScriptLoaded(
        function LoadExternalList() {
  //turn on xsite scripting support for jquery
    $.support.cors = true;
    //load the external SP list
    $("#ExternalListContainer").load("http://sourcesiteurl.aspx table.ms-listviewtable", 
        function(response, status, xhr) {
      //find all the list items and convert to HTML so we don't see the code
      $("#ExternalListContainer").find(".ms-vb2").each(function () {
             $(this).html($(this).text());
      });
    });
  }, "sp.ribbon.js");
</script>

1 Answer 1

0

Is it a regular list view? If yes, then you can set up the default behavior in the List Settings > Advanced Settings with Launch forms in a dialog? option.

Otherwise you can use SP.UI.ModalDialog.ShowPopupDialog(url) to open the link into a popup/modal or the other related methods.

EDIT

You can create a new column into your list with the type "Calculated (calculation based on other columns)". In the formula you'll enter:

="<a href='#' onclick='SP.UI.ModalDialog.ShowPopupDialog(""http://url.to/your/Lists/Name of the List/DispForm.aspx?ID="&ID&""")'>Open Modal</a>"

And "Number" for the data type.

(Don't forget to change "http://url.to/your/Lists/Name of the List/" with your own URL)

Then make sure to show this new column into the view. You'll see a link called "Open Modal" in the just-created column and when you click on that link it will open the Display Form into a modal.

6
  • AymKdn - It is a default list view. It is setup correctly and does display in a modal dialog in its home site collection. However, when I view the list from the other site collection and select an item in the list, it takes over the whole page and takes the user to the home site instead of opening the list item in a modal dialog.
    – user32090
    Commented Aug 6, 2014 at 15:05
  • AymKdn - I just noticed your other comment. How would I modify the above code to implement your suggestion?
    – user32090
    Commented Aug 6, 2014 at 15:09
  • I've edited my answer.
    – AymKdn
    Commented Aug 7, 2014 at 7:02
  • I'm still testing this, for some reason the hyperlink is broken when I view the list in the other site. I haven't had a chance to get back to it since Thursday but I will post once I've tried to fix the link. Thanks.
    – user32090
    Commented Aug 12, 2014 at 17:37
  • I can't figure out why the modal dialog link comes across as text on the external site. I'm wondering if this question would be better suited for a javascript or jquery forum. Thanks AymKdn for your help thus far.
    – user32090
    Commented Aug 21, 2014 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.