I had to solve this one quickly so I wrote a function that checks conditions for only boolean type condition/values.
//only handles true and false values now checkcondition = function(row,condition){ //used in the eval expression. If we used '=' instead of '==' we'd get an assignment error. operatermap = {}; operatermap['='] = '=='; operatermap['!='] = '!='; condVal = condition.value; //convert to string since condition values are of string type rowVal = row[condition.field].toString(); if(condVal != "true" && condVal!= "false"){ throw new Error("The condition provided is not a boolean type. Currently only boolean types are supported for checking."); } if(rowVal != "true" && rowVal!= "false"){ throw new Error("The row field provided is not a boolean type. Currently only boolean types are supported for checking."); } return eval(rowVal + operatermap[condition.operator] + condVal); }
Also some complimentary functions are:
//checks multiple conditions for a row and returns the row if it matches all conditions given //'row' is a single skuid row //'conditions' is an array of skuid conditions checkconditions = function(row,conditions){ checkconditionsWrapper = function(cond){ return checkcondition(row,cond); }; return conditions.every(checkconditionsWrapper); }; //checks multiple conditions on multiple rows and returns all rows that match all conditions //'rows' is an array of skuid data rows //'conditions' is an array of skuid conditions (you can put an array of a single condition if necessary) filterRowsByConditions = function(rows,conditions){ rowFilterWrapper = function(row){ return checkconditions(row,conditions); }; return rows.filter(rowFilterWrapper); };