More Filters using Magic hooks

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
udayvatturi
AppGini Super Hero
AppGini Super Hero
Posts: 85
Joined: 2014-06-14 03:08
Location: India
Contact:

More Filters using Magic hooks

Post by udayvatturi » 2015-02-26 19:34

Hi
Please go through the demo where you can add filters just using magic hooks.

http://test.spgon.in/filtering/Tasks_view.php
Capture.PNG
Capture.PNG (36.53 KiB) Viewed 6224 times
Tasks-tv.js

Code: Select all

jQuery(document).ready(function($) {

    var url1 = "./users.php";						//url for getting Options values from DB
    var str = '<select class="btn btn-default" name="username" id="sel1">';
    str = str + '<option value="%">All</option>';
    jQuery.ajax({
        url: url1,
        dataType: 'json',
        success: function(result) {

            for (i = 0; i < result.length; i++) {
                str = str + '<option value=' + result[i] + '>' + result[i] + '</option>';//assigning values to the dropdown with the obtained data from DB
            }

            str = str + '</select>';
            jQuery('#NoFilter').after(str);

            var str2 = '<select class="btn btn-default" name="username" id="sel2">';//manually created dropdown and its options
            str2 = str2 + '<option value="%">All</option>';
            str2 = str2 + '<option value="Open">Open</option>';
            str2 = str2 + '<option value="Close">Close</option>';
            str2 = str2 + '<option value="On-Hold">On-Hold</option>';
            str2 = str2 + '</select>';
            jQuery('#sel1').after(str2);

            var str3 = '<button id="sub_filter" type="button" class="btn btn-success">Submit</button>';
            jQuery('#sel2').after(str3);

            jQuery('#sub_filter').click(function() {
                var usr = document.getElementById('sel1').value;	//Filter value for filter1
                var type = document.getElementById('sel2').value;	//Filter value for filter2

                var filter_field1 = 9;			//filtering field number for filter1
                var filter_field2 = 10;			//filtering field number for filter2

                var url = encodeURI('Tasks_view.php?FilterField[1]=' + filter_field1 + '&FilterOperator[1]=like&FilterValue[1]=' + usr + '&FilterAnd[2]=and&FilterField[2]=' + filter_field2 + '&FilterOperator[2]=like&FilterValue[2]=' + type);
                window.open(url, "_self")
            });
        }

    });


});
Hope this helps for many people.

G Belgrado
Veteran Member
Posts: 61
Joined: 2017-03-12 09:24

Re: More Filters using Magic hooks

Post by G Belgrado » 2017-06-20 17:11

I used this code to add filters as buttons.
Works perfectly on pc and tablet browsers
but on smartphones or if you resize the browser on pc
the buttons are no longer visible.
I assume because they are not grouped with the default buttons.
Is there a way to do this or to make them visible?
Thanks

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: More Filters using Magic hooks

Post by a.gneady » 2017-07-20 11:02

There are 2 sets of top buttons that appear above the table view. One set is horizontal and appears only in large screens. The other set is vertical and appears only in smaller (mobile) screens. The code above attaches the new elements to the first set but not the second one and that's why it doesn't show in mobile screens.

To fix this, try changing the line:

Code: Select all

jQuery('#NoFilter').after(str);
To read:

Code: Select all

jQuery('[id=NoFilter]:visible').after(str);
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

G Belgrado
Veteran Member
Posts: 61
Joined: 2017-03-12 09:24

Re: More Filters using Magic hooks

Post by G Belgrado » 2017-07-20 17:09

thanks a lot

Post Reply