Ed
Posts: 0
Joined: Wed May 13, 2015 6:14 pm

List Events by Date on Results Page and Disable Expired Events by Date

Hello,

I have a Database Collection that stores Events (Event Name, Description, Event Date, Venue, Start Time, End Time, etc..).

My question is, how can I accomplish the following:

a) List the events on the Results page by Date (most recent date)?

b) Disable Events (keep from showing) after the Date has passed?

Thank you in advance!

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

List Events by Date on Results Page and Disable Expired Events by Date

Hello Ed,

a) You can sort your results by any parameter you want. Please look at the example here: https://docs.appery.io/reference#data...

b) Yes, it is possible to show results only for the selected date. Please look at the example how to use the parameter "where" with dates: https://blog.appery.io/2015/06/how-to...

Ed
Posts: 0
Joined: Wed May 13, 2015 6:14 pm

List Events by Date on Results Page and Disable Expired Events by Date

Hello Sergiy,

Answer # b above does not help with what I wish to accomplish.

I am looking for a Javascript that will only show the events with dates that are equal to or greater than the current date.

Ed
Posts: 0
Joined: Wed May 13, 2015 6:14 pm

List Events by Date on Results Page and Disable Expired Events by Date

Under mapping in the "where" JS I have the following existing script which is working fine:

var currentValue = Apperyio("Search_by_State_List").val();
var whereObject = {"venue_state_province": currentValue};
return JSON.stringify(whereObject);

What are the steps needed to ALSO add the following JS to "where" which I assume will show the events with dates that are equal to or greater than the current date?

var d = new Date();
d.setDate(d.getDate());
var dateStr = d.toISOString();
return '{"start_date":{"$gte":"'+ dateStr +'"}}';

I tried to create a new mapping and add the above JS to "where" but it did not work. I am also wondering, do I have to select "date" for the Date field (not "string") in order for the above JS to work? Thanks.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

List Events by Date on Results Page and Disable Expired Events by Date

Please check the simpler solution:

prereturn {"start_date":{"$gte":(new Date()).toISOString()}};/pre

Ed
Posts: 0
Joined: Wed May 13, 2015 6:14 pm

List Events by Date on Results Page and Disable Expired Events by Date

Thanks, but I am not sure what to do with the script that you provided. You did not really answer my question.

As mentioned above, since I already have an existing "where" JS ("Search_by_State_List"), what specific steps do I need to take to add this new JS (please be as specific as possible with the steps needed)? Do I need to create a new mapping with a new "where" JS? Please specify.

Also, regarding the source DB collection, do I have to select "date" for the Date field instead of "string" in order for the above JS to work?

Once again, please be as specific as as possible. Thank you in advance!

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

List Events by Date on Results Page and Disable Expired Events by Date

Do I need to create a new mapping with a new "where" JS?

Please use the same "where" parameter. Just add a filtering by date here: https://docs.appery.io/reference#data...

Also, regarding the source DB collection, do I have to select "date" for the Date field instead of "string" in order for the above JS to work?

Do you want to use your own column date, instead of default _createdAt? If so - yes, please change data type from "String" to "Date"

Ed
Posts: 0
Joined: Wed May 13, 2015 6:14 pm

List Events by Date on Results Page and Disable Expired Events by Date

Thanks. The filtering by date examples at the link above want you to use a specific date. However, I want to always use the present date.

Can you please show me what the final script will be when combining the two scripts below into the same "where" parameter? Thank you in advance!

var currentValue = Apperyio("Search_by_State_List").val();
var whereObject = {"venue_state_province": currentValue};
return JSON.stringify(whereObject);

var d = new Date();
d.setDate(d.getDate());
var dateStr = d.toISOString();
return '{"start_date":{"$gte":"'+ dateStr +'"}}';

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

List Events by Date on Results Page and Disable Expired Events by Date

Please use JS below for that:

prevar today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if (dd < 10) {
dd='0'+dd;
}

if(mm < 10) {
mm = '0'+mm;
}

today = new Date(mm+'/'+dd+'/'+yyyy);

var currentValue = Apperyio("Search_by_State_List")&#46;val();
return {"$and":[
{"venue_state_province": currentValue},
{"start_date":{"$gte":today&#46;toISOString()}
]};/pre

Ed
Posts: 0
Joined: Wed May 13, 2015 6:14 pm

List Events by Date on Results Page and Disable Expired Events by Date

Thank you so much Sergiy!! It is working beautifully! I appreciate very much.

One last thing I noticed though. The Events do not appear in chronological order (Starting with the closest date and Ending with the farthest date). Would you mind adding a script to the JS your provided that will also Sort the events in chronological order (Starting with the closest date and Ending with the farthest date) as per the following Example:

Example:
12-01-2016
12-10-2016
12-15-2016
01-06-2017
02-10-2017

Again, thank you for all your help!

Return to “Issues”