Default filter on a table breaks browsing all records

Please report bugs and any annoyances here. Kindly include all possible details: steps to reproduce, expected result, actual result, screenshots, ... etc.
Post Reply
jbarge
Posts: 18
Joined: 2020-01-28 18:26

Default filter on a table breaks browsing all records

Post by jbarge » 2020-01-31 14:16

Hi,

When using default filter on a table and after displaying records, if
clicking "show all" it's ok for the first page, but not with the second page
displaying default filter records.
It seems impossible to go back suppressing default filter on navigating.

I got a response proposed by Ahmed Genedy :

Hi Jean,

Thanks a lot for the clarification. So, in essence, what we need to do here is to store some flag variable ‘apply_default_filters’ as true when the user first visits the page. Default filters then need to check that flag before being applied. And whenever the user clicks ‘Show all’, that flag should be set to false.

So, to set that flag as initially true, we need to check if the user is visiting the page from somewhere else (rather than interacting with the page):

Code: Select all

if(!count($_POST) && count($_GET) <= 1) {
    // the above conditions usually indicate the user is arriving to the current table from another page
    $_SESSION['apply_default_filters'] = true;
} elseif(!empty($_REQUEST['NoFilter_x'])) {
    // the user clicked 'Show all', so let's suppress default filters
    $_SESSION['apply_default_filters'] = false;
}
Now, we need to wrap the code for applying the default filters inside a flag check:

Code: Select all

if($_SESSION['apply_default_filters'] === true) {
    // code for applying default filters
}
If you have set default filters in multiple tables, you should change the flag name to be table-specific .. otherwise it would behave unpredictably … so instead of apply_default_filters, maybe you should name it tablename_apply_default_filters (replace tablename with the name of the concerned table in each file).

I tried this code and it runs correctly
Many thanks to Ahmed

Jean André BARGE

Post Reply