Make Filters as buttons
-
- Posts: 11
- Joined: 2013-11-28 21:00
Make Filters as buttons
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.
Thank you again.
Re: Make Filters as buttons
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.
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.
Re: Make Filters as buttons
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.
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.
Re: Make Filters as buttons
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:
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.
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
});
});
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.
Re: Make Filters as buttons
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: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: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.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 }); });
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>
Re: Make Filters as buttons
Replace with:
Code: Select all
// do something when the user clicks this button
Code: Select all
window.location = 'let_view.php?FilterField%5B1%5D=4&FilterOperator%5B1%5D=like&FilterValue%5B1%5D=aaa';
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.
Re: Make Filters as buttons
a.gneady, thanks for your quick response and for this software.a.gneady wrote:Replacewith:Code: Select all
// do something when the user clicks this button
Code: Select all
window.location = 'let_view.php?FilterField%5B1%5D=4&FilterOperator%5B1%5D=like&FilterValue%5B1%5D=aaa';
Re: Make Filters as buttons
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.
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.
-
- Posts: 11
- Joined: 2013-11-28 21:00
Re: Make Filters as buttons
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
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
Re: Make Filters as buttons
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
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
Re: Make Filters as buttons
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 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.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.
Re: Make Filters as buttons
Thanks - worked perfectly!!
-
- Posts: 13
- Joined: 2015-12-16 12:54
Re: Make Filters as buttons
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!
Have you be able to do like this example, Can you share your solution.
http://test.spgon.in/filtering/Tasks_view.php
Thanks!
Re: Make Filters as buttons
What means exactly the row 'FilterField%5B1%5D=4&FilterOperator%5B1%5D=like&FilterValue%5B1%5D=aaa' ?a.gneady wrote: ↑2014-07-15 00:36Replacewith:Code: Select all
// do something when the user clicks this button
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]
ALex.
Re: Make Filters as buttons
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
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
Re: Make Filters as buttons
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.
Olaf
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",
"~!@#$%^&*(){}[]`/=?+\|-_;:'\,<.>",
'These are the problems => . \ \' \\ \\\\ \\\\\\ \\\\\\\\ "',
);
foreach ($test_case as $test_str) {
print '<script>';
print 'alert(' . escape_javascript_string($test_str) . ')';
print '</script>';
}
*/
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view