Open table with filter

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
dathanasios
Posts: 29
Joined: 2020-12-26 10:17

Open table with filter

Post by dathanasios » 2024-09-29 09:48

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

ppfoong
Veteran Member
Posts: 46
Joined: 2021-07-13 16:46

Re: Open table with filter

Post by ppfoong » 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.

dathanasios
Posts: 29
Joined: 2020-12-26 10:17

Re: Open table with filter

Post by dathanasios » 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

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1869
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Open table with filter

Post by jsetzer » 2024-10-01 12:21

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
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1869
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Open table with filter

Post by jsetzer » 2024-10-01 12:40

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 89 times

Table view
Default table view, filtered by node_id = 10

chrome_YqSbc6PjhC.png
chrome_YqSbc6PjhC.png (35.14 KiB) Viewed 89 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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

dathanasios
Posts: 29
Joined: 2020-12-26 10:17

Re: Open table with filter

Post by dathanasios » 2024-10-01 13:28

@jsetzer

Thanks a lot!

ppfoong
Veteran Member
Posts: 46
Joined: 2021-07-13 16:46

Re: Open table with filter

Post by ppfoong » 2024-10-01 14:58

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.

ppfoong
Veteran Member
Posts: 46
Joined: 2021-07-13 16:46

Re: Open table with filter

Post by ppfoong » 2024-10-01 15:04

Yet another way is using the addFilter() function as described in this page:
https://bigprof.com/appgini/tips-and-tu ... ers/part-1

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1869
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Open table with filter

Post by jsetzer » 2024-10-01 20:17

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.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

Post Reply