Selecting PDF to view from datagrid result

661
2
05-01-2012 10:19 AM
AllisonAnderson
New Contributor III
I have a datagrid that is returning the results from a spatial selection.  One of the fields contains the names of pdfs that I would like to have launch when clicked.  I've created a formatter for this field, so the user does not see the name - it's just a button.  If there is just one pdf listed in the attribute, I'm good.  But there are some features that have multiple pdfs and the user would pick which one they want to open. They are delimited by semicolons now in the attribute field.  I'm trying to figure out the best option for providing this functionality. 

Is it possible to create a dropdown list of all the pdfs and the one selected would launch?

Or do I create a dialog box that would have links to each pdf?  I'm guessing I would need to parse out the individual pdf names into an array.

I'm new to all this programming stuff and am hacking together samples to make this work.
0 Kudos
2 Replies
TomJacoby
New Contributor III
This is a little messy, but it works and should serve as an example as to how you could make this work.  I use JQuery, so hopefully that isn't an issue.

During the initialization:

map.graphics.enableMouseEvents();
dojo.connect(map.graphics, "onClick", function(evt) {
    map.infoWindow.setContent("<span id='spanSelectPDF'></span><span><input type='button' value='Open PDF' onclick='openPDF();' /></span>");
    var URLs = evt.graphic.attributes.PDFs.split(";"); // Assumes attribute's name is 'PDFs'
    if (URLs.length > 1) { // More than 1 pdf, so use a select list...
        var selectList = $("<select id='selectPDF' />");
        selectList.append($("<option selected='selected'>Select PDF</option>"));
        for (var i = 0; i < URLs.length; i++) {
             var url = URLs;
             selectList.append($("<option value='" + url + "'>" + url + "</option>"));
        }
        $("#spanSelectPDF").append(selectList);
    } else { // One (or fewer) pdfs, just put the URL in the span to display
        $("#spanSelectPDF").html(URLs[0]);
    }
});


Then the code for "openPDF()":

function openPDF() {
    var url;
    if ($("#selectPDF").length > 0) // Check if the select list exists
        url = $("#selectPDF").find("option:selected").val(); // get the value of the selected option
    else
        url = $("#spanSelectPDF").html(); // otherwise use the html we stuck in the span as the link
    if (url != "") // Check the url has a value, as our default option has no value (requires that the user make a selection)
        window.open(url); // Open the link
}


Hope this helps.
0 Kudos
AllisonAnderson
New Contributor III
Tom,

Thanks much for the response.  For the time being, I decided to keep it simple and create multiple features for each record.  Basically I had multi-part features that were causing me confusion with the programming.  My next step is to create a button that will launch the raster, so keeping it simple will help with that too.   Just a bit easier for me to wrap my mind around at the moment.  I will however keep your code in my back pocket for when this gets re-written with cleaner and more efficient code down the line... 

Allison
0 Kudos