0

How would one go about finding the correct JS/Jquery methods to accomplish the following?

I would like to retrieve the URL parameter passed to the page(the parameter being projectCode) and then using this parameter, load in the appropriate document library (there is one docLib for each project), finally it should display the recently modified/created items by the user from said document library.

For example, we have two projects, project 1 and project 2(assume both projects have their own docLibs: dl_project1 ,dl_project2). I load in the project dashboard page with the parameter: projectCode=PROJ1, the parameter for project 1. The script should find the dl_project1, and display the last 10 modified/created docs as links to edit the documents.

Thoughts?

0

On the page, insert two web parts, one for each library, and set them to show the last 10 modified items. Find the IDs of each webpart (using the developer tools) or wrap each webpart in a div with an ID you specify

Then use Javascript to extract the URL parameter and jQuery to hide the other webpart. The following code is from http://jquery-howto.blogspot.co.nz/2009/09/get-url-parameters-values-with-jquery.html

// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
} 

Then some jQuery like this:

$('DIV[id="WebpartWPQ2"]').hide();
  • If i expand this out to the point where we have 20 or so projects all filtered by parameter, hiding 19 web parts would be a bad design I do believe – Sabien Ambrose Jul 12 '16 at 17:08
  • Yes, hiding 19 web parts would be bad design, but you mentioned only two, hence the suggestion. Another approach could be to have just one document library and use the project code as metadata. Then it's a piece of cake to read the URL parameter and filter a list view web part by that project code. I think the bad design is that there are many document libraries that you still want to consolidate on one page. – teylyn Jul 12 '16 at 20:47
  • I agree that having multiple document libraries is cumbersome, but it is the design my boss chose. We have a document library for each project the company deals with. We select a picture on the home page to take you to the project dashboard, which displays all sorts of info about the project. We wanted to be able to load in either the document library itself or a view of the recently modified docs to the project dashboard and continue to use parameters as it reduces pages created by a ton as we have quite a few projects – Sabien Ambrose Jul 12 '16 at 20:56

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.