Page 1 of 1

Open table with filter

Posted: 2024-09-29 09:48
by dathanasios
Hello.
I would like to create several tabs in home page which incorporate a basic filter. E.g. New York as its city.
Image
After open the table the table much keep the 'basic' filter (City='New York') and when the user searches for anything eg. telephone the filter must be WHERE City = 'New York' AND Telephone LIKE '%555-3333%'
Image
How can apply that feature?
In hooks directory?
Best regards

Re: Open table with filter

Posted: 2024-10-01 04:56
by ppfoong
Perhaps you can create a view in MySQL showing a subset of records from Companies, and apply the filter in your view.

Re: Open table with filter

Posted: 2024-10-01 11:51
by dathanasios
ppfoong wrote:
2024-10-01 04:56
Perhaps you can create a view in MySQL showing a subset of records from Companies, and apply the filter in your view.
Thank you for your response.
Let's say I will create views with the filter. Is there any way to add them in the menu from AppGini designer?
Regards

Re: Open table with filter

Posted: 2024-10-01 12:21
by jsetzer
I'm pretty sure even without custom database views you can just add links and/or menu items pointing to filtered table views.

Remember that table views accept url parameters like TABLENAME_view.php?filterer_xyz_id=123.

Just try it in your browser address bar with your specific TABLENAME and any lookup column. Should work out of the box.

Having unserstood that feature, it's just about adding links. See docs about links-navmenu.php and links-home.php

Re: Open table with filter

Posted: 2024-10-01 12:40
by jsetzer
Example Code

Code: Select all

<!-- file: hooks/links-home.php -->
<?php

	// in this case, 'tasks' is the table name
	// node_id is a lookup column
	 $homeLinks[] = [
		'url' => 'tasks_view.php?filterer_node_id=10', 
		'title' => 'Filter by node_id (10)', 
		'description' => 'This is my custom descriptsion',
		'groups' => ['*'], 
		'icon' => getTableList(true)['tasks'][2],
	];
Dashboard
( :lol: including my quick and dirty typo in description and tooltip)
chrome_hLE3XgrRqC.png
chrome_hLE3XgrRqC.png (5.82 KiB) Viewed 48 times

Table view
Default table view, filtered by node_id = 10

chrome_YqSbc6PjhC.png
chrome_YqSbc6PjhC.png (35.14 KiB) Viewed 48 times

---
Hints and Tips
  • Note that parameter names start with filterer_ (not filter_)
  • This will work with lookups by default.
  • For other filters/restrictions, feel free to pass any parameter(s) and modify $options->QueryWhere in TABLENAME_init() hook accordingly.
  • Also, you can make use of $_SESSION variable for keeping certain filters active while logged in, unless changed.
  • As links-home.php is a standard PHP file, you can add as many different links as you need to the $homeLinks array, for example fetch all distinct values from a table, then create a link per value. Just be careful with too many records.

Re: Open table with filter

Posted: 2024-10-01 13:28
by dathanasios
@jsetzer

Thanks a lot!

Re: Open table with filter

Posted: 2024-10-01 14:58
by ppfoong
dathanasios wrote:
2024-10-01 11:51
ppfoong wrote:
2024-10-01 04:56
Perhaps you can create a view in MySQL showing a subset of records from Companies, and apply the filter in your view.
Thank you for your response.
Let's say I will create views with the filter. Is there any way to add them in the menu from AppGini designer?
Regards
Yes.

In AppGini, copy table `companies` to new table `companies_newyork`. Generate your codes and update database.

In MySQL, create view with another name first, then delete table `companies_newyork`, rename your view to `companies_newyork`. (Or try the shortcut way: delete table `companies_newyork` then only create view with the same name as `companies_newyork`)

This will work as long as the table structure is the same. If it is different, make sure your view structure is the same with your `companies_newyork` table in AppGini.

Re: Open table with filter

Posted: 2024-10-01 15:04
by ppfoong
Yet another way is using the addFilter() function as described in this page:
https://bigprof.com/appgini/tips-and-tu ... ers/part-1

Re: Open table with filter

Posted: 2024-10-01 20:17
by jsetzer
Absolutely right!

Keep in mind you may have to change indexes after reordering or inserting columns then.

That's the reason I do not recommend addFilter. Just my personal opinion.