I draw DataTable in successFunction using data from ajax call:
function loadListItems() {
var oDataUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('orders')/items?$select=ID,Title";
$.ajax({
url: oDataUrl,
type: "GET",
dataType: "json",
headers: {
"accept": "application/json;odata=verbose"
},
success: successFunction,
error: errorFunction
});
}
I get current SP user with this code:
var userid= _spPageContextInfo.userId;
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
var requestHeaders = { "accept" : "application/json;odata=verbose" };
$.ajax({
url : requestUri,
contentType : "application/json;odata=verbose",
headers : requestHeaders,
success : onSuccess,
error : onError
});
function onSuccess(data, request){
var user = data.d.Title;
console.log(user);
}
function onError(error) {
console.log("error");
}
Now how to draw a table and use this user var in table search?
$('#example').DataTable({
search: {search: user}
});
I guess I need to combine these two ajax calls into one and then use this user var but not sure how to do it.