Quantcast
Channel: DataTables 1.10 — DataTables forums
Viewing all articles
Browse latest Browse all 2364

Custom Filter Not Accepting One Condition

$
0
0

Link to test case: https://jsfiddle.net/BeerusDev/x054hvt3/53/

Hello,

So I am having this issue trying to add a condition to my custom table filter $.fn.dataTable.ext.search.push( ). I currently have one condition that works, where if the currentUserId is the same as the tableUserId, then it only shows that persons tasks. I have a condition outside of the table that determines if the current user is in the "Task Assigners" group, if they are it shows the assign a task button, if not it hides it. If the user is in that group, I want the table to show all items to them, but when I add the condition to the search.push. It still only follows the currentUserTitle condition and not both.

Here is the outside table filter:

    var assignButton = document.getElementById('button1');

    function IsCurrentUserMemberOfGroup(groupName, OnComplete) {

    var currentContext = new SP.ClientContext.get_current();
    var currentWeb = currentContext.get_web();

    var currentUser = currentContext.get_web().get_currentUser(); //getting current user and groups for custom filtering of what people can see
    currentContext.load(currentUser);

    var allGroups = currentWeb.get_siteGroups();
    currentContext.load(allGroups);

    var group = allGroups.getByName(groupName);
    currentContext.load(group);

    var groupUsers = group.get_users();
    currentContext.load(groupUsers);

    currentContext.executeQueryAsync(OnSuccess,OnFailure);

    function OnSuccess(sender, args) { //success function for finding current user and group they are in.
        var userInGroup = false;
        var groupUserEnumerator = groupUsers.getEnumerator();
        while (groupUserEnumerator.moveNext()) {
            var groupUser = groupUserEnumerator.get_current();
            if (groupUser.get_id() == currentUser.get_id()) {
                userInGroup = true;
                break;
            }
        }  
        OnComplete(userInGroup);
    }

    function OnFailure(sender, args) {
        OnComplete(false);
    }    
    }

    function IsCurrentUserHasContribPerms() { //if current user is in group, show the assignButton (Task Assigner Group) to only those people.
        IsCurrentUserMemberOfGroup("TaskAssigners", function (isCurrentUserInGroup) {
            if(isCurrentUserInGroup)
            {
                assignButton.style.display = 'inline-block';
            } else {
                assignButton.style.display = 'none';

            }
        });

    }
ExecuteOrDelayUntilScriptLoaded(IsCurrentUserHasContribPerms, 'SP.js');

The above works fine, then I try to carry it over to the search.push and nothing happens???

var thisUserTitle = $().SPServices.SPGetCurrentUser({ //get the current user Title field (AKA name field)
        fieldName: "Title",
        debug: false
    });
    
    $.fn.dataTable.ext.search.push( //custom filter to only show people 
        function(settings, searchData, index, rowData) {
            var tableUserTitle = searchData[0]; //getting the user name for each row of the datatable
            var api = $.fn.dataTable.Api('#taskTable'); //getting the table API
            //console.log(tableUserTitle);
            if (tableUserTitle == thisUserTitle) { //if the current user equals the same user in the task list row, then it only will show that users items to them so they cannot see others tasks
                return true;
            }
            if (isCurrentUserInGroup === "TaskAssigners") {
                return true;
            }
            return false; //if the current user doesn't equal the same user in the task list row, returns false boolean value and nothing shows in the table
        }
    );

Viewing all articles
Browse latest Browse all 2364

Trending Articles