I have a function called setFilter, which sets up the current filter for the kendo scheduler and looks like:
function setFilter(){
//console.log(ownerIdArr);
//console.log(typeIdArr);
//console.log(locIdArr);
//console.log(descripIdArr);
//console.log(dateIdArr);
scheduler.dataSource.filter({
operator: function(task) {
//console.log(task);
//Check for all 5 filters
if(ownerIdArr.length > 0 && descripIdArr.length > 0 && locIdArr.length > 0 && picklistIdArr.length > 0 && dateIdArr > 0)
return ($.inArray(task.location, locIdArr) >= 0 && $.inArray(task.taskId, descripIdArr) >= 0 && getInvitedUsers(task, ownerIdArr) && filterPicklists(task) && $.inArray(task.taskId, dateIdArr) >= 0);
//Check 4 filters
else if(ownerIdArr.length > 0 && descripIdArr.length > 0 && locIdArr.length > 0 && picklistIdArr.length > 0)
return (getInvitedUsers(task, ownerIdArr) && $.inArray(task.taskId, descripIdArr) >= 0 && $.inArray(task.locId, locIdArr) >= 0 && filterPicklists(task));
else if(ownerIdArr.length > 0 && descripIdArr.length > 0 && picklistIdArr.length > 0 && dateIdArr.length > 0)
return (getInvitedUsers(task, ownerIdArr) && $.inArray(task.taskId, descripIdArr) >= 0 && filterPicklists(task) && $.inArray(task.taskId, dateIdArr) >= 0);
else if(ownerIdArr.length > 0 && descripIdArr.length > 0 && locIdArr.length > 0 && dateIdArr.length > 0)
return (getInvitedUsers(task, ownerIdArr) && $.inArray(task.taskId, descripIdArr) >= 0 && $.inArray(task.location, locIdArr) >= 0 && $.inArray(task.taskId, dateIdArr) >= 0);
else if(descripIdArr.length > 0 && locIdArr.length > 0 && picklistIdArr.length > 0 && dateIdArr.length > 0)
return ($.inArray(task.taskId, descripIdArr) >= 0 && $.inArray(task.location, locIdArr) >= 0 && filterPicklists(task) && $.inArray(task.taskId, dateIdArr) >= 0);
else if(locIdArr.length > 0 && picklistIdArr.length > 0 && dateIdArr.length > 0 && descripIdArr.length > 0)
return ($.inArray(task.location, locIdArr) >= 0 && filterPicklists(task) && $.inArray(task.taskId, dateIdArr) >= 0 && $.inArray(task.taskId, descripIdArr) >= 0);
else if(locIdArr.length > 0 && ownerIdArr.length > 0 && picklistIdArr.length > 0 && dateIdArr.length > 0)
return ($.inArray(task.location, locIdArr) >= 0 && getInvitedUsers(task, ownerIdArr) && filterPicklists(task) && $.inArray(task.taskId, dateIdArr) >= 0);
//Check 3 filters
else if(ownerIdArr.length > 0 && descripIdArr.length > 0 && picklistIdArr.length > 0)
return ($.inArray(task.taskId, descripIdArr) >= 0 && getInvitedUsers(task, ownerIdArr) && filterPicklists(task));
else if(ownerIdArr.length > 0 && locIdArr.length > 0 && picklistIdArr.length > 0)
return ($.inArray(task.location, locIdArr) >= 0 && getInvitedUsers(task, ownerIdArr) && filterPicklists(task));
else if(descripIdArr.length > 0 && picklistIdArr.length > 0 && locIdArr.length > 0)
return ($.inArray(task.location, locIdArr) >= 0 && $.inArray(task.taskId, descripIdArr) >= 0 && filterPicklists(task));
else if(ownerIdArr.length > 0 && descripIdArr.length > 0 && locIdArr.length > 0)
return ($.inArray(task.location, locIdArr) >= 0 && $.inArray(task.taskId, descripIdArr) >= 0 && getInvitedUsers(task, ownerIdArr));
else if(ownerIdArr.length > 0 && descripIdArr.length > 0 && dateIdArr.length > 0)
return (getInvitedUsers(task, ownerIdArr) && $.inArray(task.taskId, descripIdArr) >= 0 && $.inArray(task.taskId, dateIdArr) >= 0);
else if(ownerIdArr.length > 0 && locIdArr.length > 0 && dateIdArr.length > 0)
return (getInvitedUsers(task, ownerIdArr) && $.inArray(task.location, locIdArr) >= 0 && $.inArray(task.taskId, dateIdArr) >= 0);
else if(ownerIdArr.length > 0 && picklistIdArr.length > 0 && dateIdArr.length > 0)
return (getInvitedUsers(task, ownerIdArr) && filterPicklists(task) && $.inArray(task.taskId, dateIdArr) >= 0);
else if(descripIdArr.length > 0 && locIdArr.length > 0 && dateIdArr.length > 0)
return ($.inArray(task.taskId, descripIdArr) >= 0 && $.inArray(task.location, locIdArr) >= 0 && $.inArray(task.taskId, dateIdArr) >= 0);
else if(descripIdArr.length > 0 && picklistIdArr.length > 0 && dateIdArr.length > 0)
return ($.inArray(task.taskId, descripIdArr) >= 0 && filterPicklists(task) && $.inArray(task.taskId, dateIdArr) >= 0);
else if(picklistIdArr.length > 0 && locIdArr.length > 0 && dateIdArr.length > 0)
return (filterPicklists(task) && $.inArray(task.location, locIdArr) >= 0 && $.inArray(task.taskId, dateIdArr) >= 0);
//Check 2 filters
else if(ownerIdArr.length > 0 && dateIdArr.length > 0)
return (getInvitedUsers(task, ownerIdArr) && $.inArray(task.taskId, dateIdArr) >= 0);
else if(descripIdArr.length > 0 && dateIdArr.length > 0)
return ($.inArray(task.taskId, descripIdArr) >= 0 && $.inArray(task.taskId, dateIdArr) >= 0);
else if(locIdArr.length > 0 && dateIdArr.length > 0)
return ($.inArray(task.location, locIdArr) >= 0 && $.inArray(task.taskId, dateIdArr) >= 0);
else if(picklistIdArr.length > 0 && dateIdArr.length > 0)
return (filterPicklists(task) && $.inArray(task.taskId, dateIdArr) >= 0);
else if(ownerIdArr.length > 0 && descripIdArr.length > 0)
return (getInvitedUsers(task, ownerIdArr) && $.inArray(task.taskId, descripIdArr) >= 0);
else if(ownerIdArr.length > 0 && locIdArr.length > 0)
return (getInvitedUsers(task, ownerIdArr) && $.inArray(task.location, locIdArr) >= 0);
else if(descripIdArr.length > 0 && locIdArr.length > 0)
return ($.inArray(task.taskId, descripIdArr) >= 0 && $.inArray(task.location, locIdArr) >= 0);
else if(descripIdArr.length > 0 && picklistIdArr.length > 0)
return ($.inArray(task.taskId, descripIdArr) >= 0 && filterPicklists(task));
else if(ownerIdArr.length > 0 && picklistIdArr.length > 0)
return (getInvitedUsers(task, ownerIdArr) && filterPicklists(task));
else if(locIdArr.length > 0 && picklistIdArr.length > 0)
return ($.inArray(task.location, locIdArr) >= 0 && filterPicklists(task));
//Else, only check for 1 filter
else if(picklistIdArr.length > 0)
return filterPicklists(task);
else if(descripIdArr.length > 0)
return $.inArray(task.taskId, descripIdArr) >= 0;
else if(ownerIdArr.length > 0 || groupIdArr.length > 0)
return getInvitedUsers(task, ownerIdArr);
else if(locIdArr.length > 0)
return $.inArray(task.location, locIdArr) >= 0;
else if(dateIdArr.length > 0)
return filterPicklists(task);
else
return false;
}
});
}
The problem is... This runs after ANY change to ANY kendo widget. Changing the scheduler view makes the filter run for every task (event), when I create/edit an event, the filter runs after I click out of EVERY field in the editor/creator (which I don't get... no filtering should be happening in the create/edit popup... only after clicking save I would think...)
The filter running so much is problematic because it runs for EVERY event... so if I have 1000+ events.......... the scheduler just drags horribly and operates so slowly.
Is there anything to be done to speed this up?