Dani
Posts: 0
Joined: Wed Jun 04, 2014 5:06 pm

Filtering a database based on user input from checkboxes and date filter

Hi there,

I'm trying to return a filtered list from by database based on a user's selections (see attached pic). I know how to query the database for one column value (e.g. Maritime), but I have no idea and can't find any documentation on:
1- how to map checkbox selections
2- how to query the database based on multiple selections.

Any help greatly appreciated:)

Thanks,
Dani
Image Image

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Filtering a database based on user input from checkboxes and date filter

Hello,

It's better to use code to read every checkbox, and on this basis choose data, for instance:
pre
var Maritime = (Apperyio("Maritime").find(":checked")!="");
var Offshore= (Apperyio("Offshore").find(":checked")!="");
/pre
Then add it to where parameter

pre var params = {};
if (Maritime){
params.Maritime = "Maritime";
}
if (Offshore){
params.Offshore= "Offshore";
}
return '{ $or: ['+JSON.stringify(params)+' ] }';/pre

Dani
Posts: 0
Joined: Wed Jun 04, 2014 5:06 pm

Filtering a database based on user input from checkboxes and date filter

Hi Alena, thanks a lot for the quick reply.
Excuse my ignorance, but where am I supposed to add this code?

Are you saying I shouldn't use mapping at all - how then do I go about getting the results displayed?

Cheers,
Dani

obullei
Posts: 0
Joined: Thu Jun 05, 2014 12:17 am

Filtering a database based on user input from checkboxes and date filter

Hello!

This reference should help you to understand query: http://devcenter.appery.io/documentat....

You can implement following steps:

1 Fill the same meanings in your checkbox fields "Value" and "Text":
2 This code you should call before calling your database query (it can be jvascript handler on "click" event of button):
prevar ar = new Array();
Apperyio("mobilecheckboxgroup_2").find(":checked").each(function( index ) {
ar[index] = $( this ).val();
});
localStorage.setItem('items',JSON.stringify(ar));/pre

3 Create such javascript code for request parameter "where" of your service: prereturn '{"Category": {"$in": ' + localStorage.getItem('items') + '}}';/pre

Dani
Posts: 0
Joined: Wed Jun 04, 2014 5:06 pm

Filtering a database based on user input from checkboxes and date filter

Great, that works perfectly, thanks so much for your help!

Return to “Issues”