Mobile: 'filter' model by date, and scroll through dates on swipe

  • 1
  • Question
  • Updated 4 years ago
  • Answered
Goal: On load of mobile page show events where the Date__c field is today. Swipe left to see events for the next day; swipe right to see events for the previous day.

Since the mobile page builder doesn't have tables and filters, I'm using javascript to interact with a condition on the model. The model starts with filterable condition Date__c = 'TODAY'

I wrote the following nextDay snippet:

var model = skuid.$M('ApptInteractions'),
    condition = model.getConditionByName('Date'),
    curDate = condition.value;
    
var jsDate = skuid.time.parseSFDate(curDate);
jsDate.setDate(jsDate.getDate()+1);
var nextDate = skuid.time.getSFDate(jsDate);
model.setCondition(condition, nextDate);
model.updateData();
The problem I'm running into is that condition.value = 'TODAY', which apparently is not a date. So I end up with jsDate = FALSE.

I could use the Date__c field from the first row in the model to get curDate, but there may be a situation where there aren't any rows in the model, and I still want to be able to see the new and previous.

Anyone see a way around this?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 4 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Write an if statement to look for 'TODAY'. If so, then create a javascript date object for today.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Brilliantly simple. Thanks!
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Running into another problem. I can set the filter value to a date, but none of my rows with that date are showing up. I think it is because the field is a DateTime?

Is there any way to communicate to the filter "this day at any time?" Rather than "This date at a specific time."
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Create a formula field on the object to calculate the date from the date time field. Then use this in your model.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Perfect.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Pat.  You are approaching guru status.