Apply a default filter on a table

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
A Bindi
Veteran Member
Posts: 51
Joined: 2018-01-04 18:45

Apply a default filter on a table

Post by A Bindi » 2019-01-16 14:31

I applied the interesting article "Applying a default filter on a table" (https://bigprof.com/appgini/tips-and-tu ... ult-filter) modifying the tablename_init hook as described, and indeed it seems to run correctly, but a problem appears when iI want to remove the filter to see all the records.

Pratically when i click on "Show All" button all records are correctly shown, BUT only on first page ! In fact when i switch on second page the table is listed with the filter applied again; if in that second page I click on "Show All" button again the first page is re-listed. :(

Is there a solution ?

ALex.

sjohn
Veteran Member
Posts: 86
Joined: 2018-05-23 09:32

Re: Apply a default filter on a table

Post by sjohn » 2019-01-17 11:48

This is a catch 22 - but as it is an initial filter, then when paging the same thing happens as with eventual "marked/checked" records - it is a new page-load.

If it is a table with not too many records, you could maybe use the fantastic "scroll" suggested by pböttcher : https://forums.appgini.com/phpbb/viewto ... f=4&t=2673

You could have the scrolling for 50-100 records and still have the paging. But the problem with paging will still be there.

Another way is to make a view in a "parallel" table that is filtered. But then the initial filtering will be there always. You can still filter, but it will be in the filtered table.

The normal unfiltered table will still be available, so you could have two tables shown - one with the pre-defined filtering and the other without. You still only have to maintain one table.

If the static filter is not an option, then I think you need some code that can check if you are on page 1 or not, and then only let the filter be active on page 1. This will also mean that when paging back to page one, the filter will be active again.
I cannot help with such eventual code.

A Bindi
Veteran Member
Posts: 51
Joined: 2018-01-04 18:45

Re: Apply a default filter on a table

Post by A Bindi » 2019-01-23 15:04

Thank you very much for suggestions, very intersting.

Unfortunately it seems to do not exists a real solution to the problem, only workarounds ... :(

ALex.

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

Re: Apply a default filter on a table

Post by a.gneady » 2019-01-24 14:26

Hmm ... If I understand correctly, you don't want to force the initial filter ... you just want it to be an optional default filter applied when users initially access the table, but they can choose to remove it and see all records. In this case, a better approach instead of the code in the tablename_init hook is to modify the link to the table in the homepage and the navigation menu ... It can be done through JavaScript code placed in hooks/footer-extras.php ... something like this:

Code: Select all

<script>
	$j(function() {
		// change the link below to your desired initial filter
		var filteredLink = 'tablename_view.php?FilterField[1]=3& ...';

		$j('[href^="tablename_view.php"]').attr('href', filteredLink);
	})
</script>
Change tablename above to the concerned table name and change the filter link to the desired initial filter.
: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.

Post Reply