0

I am displaying the results using REST API from list using following code. have one status columns in list and have one status webproperty in web part properties with values New/Approve/Reject but i have to display the results based on selected value from drop-down in web properties. Here is my function to display results.

function getResults() {

 var requestUri = appweburl "/_api/SP.AppContextSite(@target)/web/Lists/getByTitle('listName')/items?&@target='" + hostweburl + "'";

    var executor = new SP.RequestExecutor(appweburl.toLowerCase());

    executor.executeAsync({
        url: requestUri,
        method: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },
        success: successHandler,
        error: errorHandler
    });
}

What would be the convenient wayt to change the requestUri so i can filter results based on one of three values from drop down .

1 Answer 1

2

You can apply filter in the onchange of your drop-down. If your column name is Status, then it should look like

$filter=Status eq "Selected value from drop-down"

Example

I guess your HTML is

<select name="" id="filter" onchange="applyFilter()">
  <option value="New">New</option>
  <option value="Approve">Approve</option>
  <option value="Reject">Reject</option>
</select>

No in the JS code, add following

function applyFilter(){
    var selectedFilter = document.querySelector("#filter").value;
    var requestUri = appweburl "/_api/SP.AppContextSite(@target)/web/Lists/getByTitle('listName')/items?$filter=status eq '"+selectedFilter+"'&@target='" + hostweburl + "'";
    getResults(requestUri);
  }

function getResults(requestUri) {

    var executor = new SP.RequestExecutor(appweburl.toLowerCase());

    executor.executeAsync({
        url: requestUri,
        method: "GET",
        headers: { "ACCEPT": "application/json;odata=verbose" },
        success: successHandler,
        error: errorHandler
    });
}

To find more about $filter, have a look CRUD Operation to List Using SharePoint 2013 Rest API

5
  • I have tried above but its not working .Not getting results .
    – meer
    Commented Jan 18, 2016 at 12:31
  • Can you update your question with what you have tried? Commented Jan 18, 2016 at 12:44
  • i have tried with the following query as u mentioned in your answer .iam getting value from dropdown but it dont display results . var requestUri = appweburl "/_api/SP.AppContextSite(@target)/web/Lists/getByTitle('listName')/items?$filter=status eq '"+selectedFilter+"'&@target='" + hostweburl + "'";
    – meer
    Commented Jan 18, 2016 at 13:27
  • what about the html? Is it same as mine? Commented Jan 18, 2016 at 13:30
  • no i have dropdown in app part propery and iam getting value from webpart property by usingas follows selectedFilter = getQueryStringParameter("Status");
    – meer
    Commented Jan 18, 2016 at 15:51

Your Answer

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

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