Open xzegga opened 11 years ago
The default "Query" method in the Controller has a bunch of built-in ways that you can filter through the API. You can do almost any type of basic query through the API. If you need even more advanced querying you can just write your own logic in the "Query" Method too. Here are some URLs, for example:
// get the record where the Id equals 10
http://localhost/cargo/api/packages?Id_Equals=10
// get all records where the description contains the text "material"
http://localhost/cargo/api/packages?Description_IsLike=material
// also you can combine the criteria, as many as you need:
http://localhost/cargo/api/packages?Service_Equals=ground&Id_GreaterThan=5
The only part you need to write yourself is the client HTML and Javascript code to add the drop-downs to your page and then pass that information along to the REST service. Where you are going to want to look is the /scripts/app/tablename.js
file and you should look at the variable page.fetchParams
which is what stores the state for the query filter settings as well as what page of the results is current.
:+1: Great solution Jason, work beautifull, I will post in the future how I have resolved this with a partial or complete solution code.
Regards
Dear again, I have another question about this topic, what about If I want to evaluate with 'AND' statement in the query, for example: if I want to get records for Id_Equals=10 AND Id_Equals=15?
Regards.
In my third example URL it will be doing an AND query. Did you mean you want to do an OR query?
Yes I see, but I need to filter the query by two values for the same param
For example: Id_Equals=10 Id_Equals=15
thanks for your help :)
Regards
I actually just now made a commit to phreeze dae801db02ebbfcef352ea58b225c2c3ffd57d30 if you make sure to update then you'll be able to use the _In criteria in your URL like this:
http://localhost/cargo/api/packages?Service_Equals=ground&Id_In=10,15
Great, it's amazing :+1:
There is a problem with this functionality on packed .phar file, with phreeze folder work well, but with phreeze-3.3.phar not work.
I most likely didn't build a new .phar with that update yet but you can generate your own .phar from the most recent source by running phreeze/phar/build.php from the command line. That will give you a .phar with all the most recent updates. At some point I'll do an official 3.4 phar or something as well, but that way if you need something immediate from the source then you definitely can build a phar file for that.
Hi! i want to do the same thing..i want to put 4 drop down lists, so the user can be more specific on its search..Please heeelp..xzegga let us know if you ve made it...what about the 3.3 version?
It's not really too tough to do that but it does require digging into two places. First you have to add your dropdowns to the template. The next thing you have to do is to edit the javascript that goes with that page (for example, Customers has a file scripts/app/customers.js).
The template is basically just adding your drop-downs HTML. The javascript is where you have to do any significant work. You should be able to somewhat copy the code from the existing filter which looks something like this:
// initialize the search filter
$('#filter').change(function(obj){
page.fetchParams.filter = $('#filter').val();
page.fetchParams.page = 1;
page.fetchCustomers(page.fetchParams);
});
The fetchParams is just a list of variables that get sent to the server. So you just need to add whatever you want sent to the controller Query method.
See my posts above beginning with 'The default "Query" method' to see examples of parameters that you could add, for example: Service_Equals=ground or Level_GreaterThan=3 , etc.
Hope that makes sense. It's not that difficult, but definitely requires going into the code and understanding how the filter works. Once you do that it's pretty easy to make changes to it.
Ok. so ive made a form with get method with the 4 dropdownlists, now when i hit search the url is changing to /secureadmin?nomos=attica&asfalish=ika&eidikothta=education&pistopoihsh=eoppep what should i do now?? please any examples
ps i moved the search listing on the secureadmin page so the user can see the list only if logged in
Basically you need to pass through the values from your drop-down to the REST API. It's going to require going into the Javascript code and getting familiar with how the existing filter field works. Once you have that, it should make more sense and you will probably have more specific questions that we can answer here.
Unfortunately I don't really have any example code to show how to do specifically what you want. On the videos page at http://phreeze.com/phreeze/documentation/videos.php there is a video called "Example: CriteriaFilter" which will show you how the back-end part of the filter works.
have you got any start up examples based on my problem?? thank you!
I want to put a three dropdowns to top of record list, country, zone and province instead of default search filter, how i can filter the results by specific field instead of default CriteriaFilter?
Regards