Make Filters as buttons

Wish to see a specific feature/change in future releases? Feel free to post it here, and if it gets enough "likes", we'd definitely include it in future releases!
Post Reply
scorpio_x73
Posts: 11
Joined: 2013-11-28 21:00

Make Filters as buttons

Post by scorpio_x73 » 2014-01-29 22:30

It would be nice when you save a filter to have the option to assign this filter to a a button in the relevant table (it can have 3 default places for filters so we can assign the filter we ant to one of the three buttons)

Thank you again.

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

Re: Make Filters as buttons

Post by a.gneady » 2014-03-01 08:40

You can use the table_header or table_footer hooks to insert the button into the page. In future releases, I plan to add an option to allow users to "bookmark" filters for easy access later.
:idea: Calendar plugin: Organize your data into beautiful calendars.
:arrow: Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
:arrow: Summary Reports plugin: Build powerful reports and charts for your AppGini apps.
:arrow: Search Page Maker: Compose user-friendly yet powerful search pages for your AppGini apps.

xithyl
Posts: 3
Joined: 2014-07-13 13:19

Re: Make Filters as buttons

Post by xithyl » 2014-07-13 13:24

Dear a.gneady

Can you please explain how can we add custom filters as a buttons to specific table views (table_header) ? It would be nice to see the example of that.

Thank you.

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

Re: Make Filters as buttons

Post by a.gneady » 2014-07-13 21:33

I'll try to write a detailed tutorial on this topic ... but here is a starting point ... in the generated "hooks" folder, create a file and name it "tablename-tv.js" (where tablename is the name of the table you want to add the button in) ... this file will be automatically executed in the table view of the table. Add this JavaScript code to the file:

Code: Select all

jQuery(function(){
	jQuery('#Filter').after('<button class="btn btn-default" type="button" id="foebar"><i class="glyphicon glyphicon-ok"></i> Foe bar</button>');
        jQuery('button[id=foebar]').click(function(){
              // do something when the user clicks this button
        });
});
The above code would add a new button next to the "Filter" button and label it "Foe bar" .. I hope this would get you started.
:idea: Calendar plugin: Organize your data into beautiful calendars.
:arrow: Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
:arrow: Summary Reports plugin: Build powerful reports and charts for your AppGini apps.
:arrow: Search Page Maker: Compose user-friendly yet powerful search pages for your AppGini apps.

xithyl
Posts: 3
Joined: 2014-07-13 13:19

Re: Make Filters as buttons

Post by xithyl » 2014-07-14 10:32

a.gneady wrote:I'll try to write a detailed tutorial on this topic ... but here is a starting point ... in the generated "hooks" folder, create a file and name it "tablename-tv.js" (where tablename is the name of the table you want to add the button in) ... this file will be automatically executed in the table view of the table. Add this JavaScript code to the file:

Code: Select all

jQuery(function(){
	jQuery('#Filter').after('<button class="btn btn-default" type="button" id="foebar"><i class="glyphicon glyphicon-ok"></i> Foe bar</button>');
        jQuery('button[id=foebar]').click(function(){
              // do something when the user clicks this button
        });
});
The above code would add a new button next to the "Filter" button and label it "Foe bar" .. I hope this would get you started.
a.gneady; Thank you for your quick reply. By following your explanations above, I added the buttons without any problems. Now how can i trigger the saved filters? Sorry, but my php knowledge is zero. Should i use the following code:

Code: Select all

<form method="post" action="http://localhost/deb/let_view.php">
	<input name="FilterAnd[1]" value="" type="hidden">
	<input name="FilterField[1]" value="4" type="hidden">
	<input name="FilterOperator[1]" value="like" type="hidden">
	<input name="FilterValue[1]" value="aaa" type="hidden">


	<input type="submit" value="Show Filtered Data">
</form>
Thanks in advance for your reply.

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

Re: Make Filters as buttons

Post by a.gneady » 2014-07-15 00:36

Replace

Code: Select all

// do something when the user clicks this button
with:

Code: Select all

window.location = 'let_view.php?FilterField%5B1%5D=4&FilterOperator%5B1%5D=like&FilterValue%5B1%5D=aaa';
:idea: Calendar plugin: Organize your data into beautiful calendars.
:arrow: Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
:arrow: Summary Reports plugin: Build powerful reports and charts for your AppGini apps.
:arrow: Search Page Maker: Compose user-friendly yet powerful search pages for your AppGini apps.

xithyl
Posts: 3
Joined: 2014-07-13 13:19

Re: Make Filters as buttons

Post by xithyl » 2014-07-16 10:31

a.gneady wrote:Replace

Code: Select all

// do something when the user clicks this button
with:

Code: Select all

window.location = 'let_view.php?FilterField%5B1%5D=4&FilterOperator%5B1%5D=like&FilterValue%5B1%5D=aaa';
a.gneady, thanks for your quick response and for this software. :)

tmathew
Posts: 7
Joined: 2015-03-19 02:14

Re: Make Filters as buttons

Post by tmathew » 2015-05-24 13:56

I have added few buttons after 'Add New' in tablename-tv.js. Works perfectly ok. But when I reduced the size of window to check how it appears on Tablets & Mobiles, all newly added buttons disappeared and only the 'Add New' button displayed.

Now I made the 'Add New' button hidden and checked. Surprisingly the display is exactly same as before -- means it displayed 'Add New' button alone, even though I made it hidden. Its displaying perfectly ok (without the hidden AddNew button) when the window is maximized.

Is it due to the absence of any include files in the tablename-tv.js file? Or did I miss out something else?

An immediate advice/help will be highly appreciated.

scorpio_x73
Posts: 11
Joined: 2013-11-28 21:00

Re: Make Filters as buttons

Post by scorpio_x73 » 2015-07-22 10:20

Ahmad thank you for all the replies this piece of code is SUPER.

But we still have problem with the responsiveness. When we make the screen smaller the buttons are disappear .

Do we have to make changes somewhere else also ?

Thank you in advance

gonzalo
Posts: 11
Joined: 2015-08-24 14:42

Re: Make Filters as buttons

Post by gonzalo » 2015-10-13 22:21

Hi:

Any further developments on this mater? I tried using this and I can't get it to work - I get an error when the window.location line is executed. My statement is like this:

window.location = 'let_view.php?FilterField%5B1%5D=9&FilterOperator%5B1%5D=like&FilterValue%5B1%5D="In Use"';

I found a solution in another post that seems quite elegant, but my limited PHP / JS abilities do not allow me to get it to work.

http://test.spgon.in/filtering/Tasks_view.php

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 250
Joined: 2013-03-21 04:37

Re: Make Filters as buttons

Post by peebee » 2015-10-13 23:59

I tried using this and I can't get it to work - I get an error when the window.location line is executed. My statement is like this:

window.location = 'let_view.php?FilterField%5B1%5D=9&FilterOperator%5B1%5D=like&FilterValue%5B1%5D="In Use"';
If that is the exact code you are using, you will need to change 'let_view.php? to the table table name concerned (unless of course your table name is actually named 'let')

(i.e.: window.location = 'YOURTABLENAMEHERE_view.php?FilterField%5B1%5D=9&FilterOperator%5B1%5D=like&FilterValue%5B1%5D="In Use"')

You will likely also need to change the specific filter fields & filter operators depending on the result you are after?

The code example provided by Ahmad is specific to the requirements of the op who asked the question.

gonzalo
Posts: 11
Joined: 2015-08-24 14:42

Re: Make Filters as buttons

Post by gonzalo » 2015-10-14 15:03

Thanks - worked perfectly!!

Authen-TIC
Posts: 13
Joined: 2015-12-16 12:54

Re: Make Filters as buttons

Post by Authen-TIC » 2015-12-16 12:56

Hi Gonzalo,

Have you be able to do like this example, Can you share your solution.

http://test.spgon.in/filtering/Tasks_view.php

Thanks!

A Bindi
Posts: 25
Joined: 2018-01-04 18:45

Re: Make Filters as buttons

Post by A Bindi » 2021-04-30 13:26

a.gneady wrote:
2014-07-15 00:36
Replace

Code: Select all

// do something when the user clicks this button
with:

Code: Select all

window.location = [size=150][b]'let_view.php?FilterField%5B1%5D=4&FilterOperator%5B1%5D=like&FilterValue%5B1%5D=aaa';[/b][/size]
What means exactly the row 'FilterField%5B1%5D=4&FilterOperator%5B1%5D=like&FilterValue%5B1%5D=aaa' ?

ALex.

pfrumkin
Veteran Member
Posts: 119
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Make Filters as buttons

Post by pfrumkin » 2021-04-30 16:05

Hi Alex,

That is the querystring, effectively passing in values to the php script. It is telling the php script how to perform the SQL query, defining the WHERE clause, WHERE field #4 LIKE 'aaa'.

I think it is the SortFields array in the tablename_view.php that maps the field # to the field in the table.

The %5B and %5D are html encoding for characters, so that the browser passes those characters to the script literally rather than interpreting them. See something like https://en.wikipedia.org/wiki/Percent-encoding for more explanation.

Hope that helps.

~Paul

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 949
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: Make Filters as buttons

Post by onoehring » 2021-05-02 06:55

Hi,

if you want to generate JS from within PHP, I find it useful to call the following function to make sure, all characters are properly escaped. Please see the source ( https://gist.github.com/Chengings/9599473 ) for more information.

Code: Select all

/**
* Escape php string to javascript string
* @param string $str
* @return string escaped string
* src: https://gist.github.com/Chengings/9599473
*/
function escape_javascript_string($str){
	// if php supports json_encode, use it (support utf-8)
	if (function_exists('json_encode')) {
		return json_encode($str);
	}
	// php 5.1 or lower not support json_encode, so use str_replace and addcslashes
	// remove carriage return
	$str = str_replace("\r", '', (string) $str);
	// escape all characters with ASCII code between 0 and 31
	$str = addcslashes($str, "\0..\37'\\");
	// escape double quotes
	$str = str_replace('"', '\"', $str);
	// replace \n with double quotes
	$str = str_replace("\n", '\n', $str); 
	return "'{$str}'";
}
/* for testing:
$test_case = array(
	'',
	"https://demo/path/download.html?q=query",
	"[email protected]#$%^&*(){}[]`/=?+\|-_;:'\,<.>",
	'These are the problems => . \ \' \\ \\\\ \\\\\\ \\\\\\\\ "',
);
foreach ($test_case as $test_str) {
	print '<script>';
	print 'alert(' . escape_javascript_string($test_str) . ')';
	print '</script>';
}
*/
Olaf

Post Reply