Skip to main content

Hi,

I wonder if anyone found a simple enough solution to this

My goal: Trying to have a dashboard which contains data from multiple objects/models
and have he ability to filter using a date range among other filters

I’ve done a similar request in the past , but it was just to pass 1 data 
Now not really sure how to do this for a date range…

Here’s what I used in the past.
Any ideas? preferably without JS , but if no choice…

Thank you

The solution we use is js because we also haven’t found a clean way around this.

I post a sample on this thread:
https://community.skuid.com/t/filtering-multiple-models-using-a-single-set-of-filters-glo…


My example doesn’t have any dates in it, but I would caution you to be aware of date/time formats.  We tend to give UI fields for our users to specify a date range (Show me Opportunities created ‘From Date’ to ‘End Date’) and create date in SF is a date/time, while my UI fields are just Date.

To get around that, we’ve put Salesforce formula fields on our objects “Create Date Only” that just returns the date only of the created date and time.

Here’s another sample using Date From and Date To UI fields from a UI or dummy model that affects 2 different models on your page.


var params = arguments>0],            $ = skuid.$;
                       
var FilterModel = skuid.model.getModel(‘myFilterModel’);
var FilterRow = FilterModel.getFirstRow();
           
//Search Fields from Search Model
var dateFromVar = FilterModel.getFieldValue(FilterRow,‘CreateDateFrom’,true);
if (dateFromVar === “”) {dateFromVar = null;}

var dateToVar = FilterModel.getFieldValue(FilterRow,‘CreateDateTo’,true);
if (dateToVar === “”) {dateToVar = null;}

// declare models that are affected by the date range and empty them
var myModel1 = skuid.model.getModel(‘myModel1Name’);
myModel1.emptyData();
var myModel2 = skuid.model.getModel(‘myModel2Name’);
myModel2.emptyData();

//Declare condition variables - from Model 1
var dateFromCondition1 = myModel1.getConditionByName(‘CreateDateFrom1’);
var dateToCondition1 = myModel1.getConditionByName(‘CreateDateTo1’);
//Declare condition variables - from Model 2
var dateFromCondition2 = myModel2.getConditionByName(‘CreateDateFrom2’);
var dateToCondition2 = myModel2.getConditionByName(‘CreateDateTo2’);

//deactivate conditions to start
myModel1.deactivateCondition(dateFromCondition1, false);
myModel1.deactivateCondition(dateToCondition1, false);

myModel2.deactivateCondition(dateFromCondition2, false);
myModel2.deactivateCondition(dateToCondition2, false);
 
// Check for Search field values.  If a value exists, set the results model condition
if(dateFromVar !== null) {myModel1.setCondition(dateFromCondition1, dateFromVar, false);}
if(dateToVar !== null) {myModel1.setCondition(dateToCondition1, dateToVar, false);}

if(dateFromVar !== null) {myModel2.setCondition(dateFromCondition2, dateFromVar, false);}
if(dateToVar !== null) {myModel2.setCondition(dateToCondition2, dateToVar, false);}

// query models with conditions set
skuid.model.updateData()myModel1,myModel2],function(){
    console.log(‘update data complete!’);  
});


Thank you Chandra for quick answer , I will test it ASAP 🙂


HI Chandra,

Thank you for sample I just tried with 2 models, and it worked like a charm

Now I have 1 more question, I was planning on using 2 of those Js snippet 

as I need 2 different conditions that may be selected. first being the range , the other to select the “User”

The problem from what i can see is that in your JS there’s a function to empty models , so i guess this will not allow me to do idea listed above if trying to use both filters with 2 different JS snippets.

as there is some cases, where I do not want to select a user (want to see stats for all users) and select a range, sometimes the opposit, and other times both conditions.

Prob would need a way to incorporate this logic in the same snippet?

In case that yes and you have a similar sample, i would greatly appreciate a copy, as not very good at js 😦

Thank you


Hi Dave, You can just expand this same snippet to use as many filters as you want.  The way the snippet is written, if the user puts a value in the filter field - it uses it.  If they don’t, it ignores it.  So in your case, they might specify a date range but not a user… that’s fine, user will be ignored if Null.

So, add a UI field to your filter model called User, make it a reference to the user object.  Then create user conditions on your 2 models that you want to affect, and set those to off by default.

Then copy the syntax from the date fields in these places:

//Search Fields from Search Model
var userVar = FilterModel.getFieldValue(FilterRow,‘User’,true);
if (userVar === “”) {userVardateFromVar = null;}




//Declare condition variables - from Model 1
var UserCondition1 = myModel1.getConditionByName(‘User1’);

//Declare condition variables - from Model 2
var UserCondition2 = myModel2.getConditionByName(‘User2’);


//deactivate conditions to start
myModel1.deactivateCondition(UserCondition1, false);

myModel2.deactivateCondition(UserCondition2, false);
 
// Check for Search field values.  If a value exists, set the results model condition
if(userVar !== null) {myModel1.setCondition(UserCondition1userVar, false);}

if(userVar !== null) {myModel2.setCondition(UserCondition2userVar, false);}



Chandra,

Thank you very much for detailed explanation and sample,

it all works like a charm now!

I appreciate you taking the time 🙂