0

I have a list named childribbon and in the new form of this list I have added the same list which is being displayed in display form, enter image description here

If I set the Employee to Nderon Hiseni in my childribbon new fort

I want only items with Nderon Hiseni to be displayed in my childribbon display form?

How Can I do this with javascript?

5
  • Use sharepoint rest api or jsom to get the filtered items. Commented Aug 18, 2016 at 13:07
  • How Can I make this? Commented Aug 18, 2016 at 13:09
  • Can you explain me because I am new to sharepoint! Commented Aug 18, 2016 at 13:09
  • Does Employee field show the title from the lookup field? Commented Aug 18, 2016 at 13:11
  • No Employee field is looked up by another list column Commented Aug 18, 2016 at 13:12

2 Answers 2

1

If this is one webpage then you can

  • Add an onchange eventhandler on the drop down <select>
  • Then use a JS standard document.querySelector to find the matching elements in the list
  • You then loop all elements, find the parent TR row, and hide

Something like: disclaimer: didn't not test this code, you are on your own

document.getElementById('mySelect').addEventListener('onchange', function () {
    var employeeName = this.value;
    var matches = document.querySelector("a[href*=" + employeeName + "']");
    matches.forEach(function (match) {
        var row = GetAncestor(match, 'TR');
        row.style.display='none';
    });
});
  • GetAncestor is provided by SharePoint
  • You have to add ...display='block' yourself to show rows again
  • forEach might need a Polyfill in older IE versions
-1

Sharepoint rest api example if Employee is a lookup field and it displays the Title

var url= "/_api/Web/Lists/GetByTitle('childribbon')/Items?"+
           "$select=ID,Title,Employee/Title,Skills"+
           "&$expand=Employee&$filter=Employee/Title eq 'Nderon Hiseni'";
$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + url,
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function (data) {
        console.log(data.d.results);
    },
    error: function (error) {
        alert(JSON.stringify(error));
    }
});

Otherwise, if Employee is not a lookup field then the url should be

var url= "/_api/Web/Lists/GetByTitle('childribbon')/Items?"+
           "$select=ID,Title,Title,Skills"+
           "&$filter=Employee eq 'Nderon Hiseni'";

You can read this article for better understanding http://www.codeproject.com/Articles/990131/CRUD-Operation-to-List-Using-SharePoint-Rest-API

2
  • I want it to be dynamically not static, I have set a cookie with can I use that cookie to display user? Commented Aug 18, 2016 at 13:21
  • 1
    write a function and pass a variable which contains the employee name. Then call ajax with the variable Commented Aug 18, 2016 at 13:23

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.