sharepoint0520
asked on
Generate the Dynamic REST API url in sharepoint 2013
Hi,
We have sharepoint list view where user filter and sort data. Now we would like get sorting and filter parameters and generate rest api url by script editor to fetch some list items. is it possible to read filter and sorting parameter by url or ctx object?
There is a object ctx.ListData.Filterlink gives some parameters but it's in another format.
"?FilterField1=LinkTitle&F ilterValue 1=A&SortFi eld=LinkTi tle&SortDi r=Asc&Page View=Share d&"
Here is the REST Api url where i need to add filter and sorting parameters.
url: siteUrl + "/_api/lists/getbytitle('T est_Custom _List')/It ems?$selec t Title",
We have sharepoint list view where user filter and sort data. Now we would like get sorting and filter parameters and generate rest api url by script editor to fetch some list items. is it possible to read filter and sorting parameter by url or ctx object?
There is a object ctx.ListData.Filterlink gives some parameters but it's in another format.
"?FilterField1=LinkTitle&F
Here is the REST Api url where i need to add filter and sorting parameters.
url: siteUrl + "/_api/lists/getbytitle('T
<script>
var siteUrl = window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl;
jQuery.ajax({
// need to generate dynamic url based on filter and soting on page
url: siteUrl + "/_api/lists/getbytitle('Test_Custom_List')/Items?$select Title",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
"content-type":"application/json;odata=verbose",
"X-RequestDigest": jQuery("#__REQUESTDIGEST").val()
},
success: function(d) {
var stringData = JSON.stringify(d);
var jsonObject = JSON.parse(stringData);
var results = jsonObject.d.results;
for(i = 0; i < results.length;i++) {
console.log(results[i]["Title"])
}
},
error: function() {
console.log('fail');
}
});
</script>
ASKER
Hi,
I have to generate filter and sorting parameter dynamically by reading the current url. For instance user filter and sort the sharepoint listview so url will change. Now we have to read that url and fetch filter and sort parameter and generate the url for rest api uri. In below url i have filter by name and sort by Employee ID.
https://sharepoint.com/sites/TeamSite/Lists/Employee/Test.aspx#InplviewHash7e69bb93-ffcc-4b23-b598-93de4e891d5c=SortField%3DEmployee_x0020_ID-SortDir%3DAsc-FilterField1%3DLinkTitle-FilterValue1%3Dtitle1
So my requirement is to read current url and generate rest api url.
Let me know if you still have any confusion.
I have to generate filter and sorting parameter dynamically by reading the current url. For instance user filter and sort the sharepoint listview so url will change. Now we have to read that url and fetch filter and sort parameter and generate the url for rest api uri. In below url i have filter by name and sort by Employee ID.
https://sharepoint.com/sites/TeamSite/Lists/Employee/Test.aspx#InplviewHash7e69bb93-ffcc-4b23-b598-93de4e891d5c=SortField%3DEmployee_x0020_ID-SortDir%3DAsc-FilterField1%3DLinkTitle-FilterValue1%3Dtitle1
So my requirement is to read current url and generate rest api url.
Let me know if you still have any confusion.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
This should be pretty simple just to add a filter and sorting parameters.
https://www.c-sharpcorner.com/article/sharepoint-2013-using-rest-api-selecting-filtering-sortin/
Is it something that you are looking.
If you can provide more details?