Custom Filter Question
Custom Filter Question
zgoforth
Posts: 493Questions: 98Answers: 2
No test case yet, but I wanted to see if this was even possible.
I want to make a custom filter, where I get the current user of SharePoint's ID/Title/Name and only display values in the DataTable that include their name as I am using a SharePoint person field to populate who each task is assigns a hidden user ID column to the table. If I can get that current user's id, can I apply it to the filter linked above?
if (currentUserId === AssignedTo.results[0].Id){
return true;
}
return false;
Answers
There is nothing special about the search plugin. Its just a Javascript function the is called for each row. If you have the values you can use them in the function like any other function.
Kevin
couldn't you add it to the server side in a where statement?
@montoyam unsure never done that?
@kthorngren so I did the following:
When I console thisUserID it is 32, when I check rowData[0] 32 is there but so is another ID of another user and I do not want to see their data, just mine.
But when I implement it, I cannot see any of the data as it is all filtered out? I have created a filter before to show the current week items only and it worked fine. Am I missing something here?
does this help?
https://datatables.net/forums/discussion/67288
@montoyam I am not using php though
That suggests your if statement in line 15 is always false so the return in line 18 is executed which hides the row.
Hard to say without seeing the data. Maybe your are comparing a string to an numeric value which won't work with
===
. You can try==
. Please build a simple example, ie, leave out the RowGroup and other stuff we aren't troubleshooting, with a same of your data so we can take a look.Kevin
@kthorngren tried that, still says no No matching records found. Creating a test case as we speak.
Are you using Editor? How are you getting the SharePoint data?
@montoyam REST API
@kthorngren Here is my fiddle: https://jsfiddle.net/BeerusDev/x054hvt3/7/
You added
thisUserID
as a parameter for the search plugin function:This is causing the variable to be undefined. See this example:
https://jsfiddle.net/5ykj82d0/
Remove the extra parameters
, thisUserID, thisUserTitle
from the function and your example will work. For example:https://jsfiddle.net/5ykj82d0/1/
Kevin
@kthorngren Oh my goodness, thank you. Not sure why I tried passing them through the params when they are already globally defined....