Page 1 of 1

Apply a default filter on a table

Posted: 2019-01-16 14:31
by A Bindi
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.

Re: Apply a default filter on a table

Posted: 2019-01-17 11:48
by sjohn
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.

Re: Apply a default filter on a table

Posted: 2019-01-23 15:04
by A Bindi
Thank you very much for suggestions, very intersting.

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

ALex.

Re: Apply a default filter on a table

Posted: 2019-01-24 14:26
by a.gneady
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.