Add button on table view page

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
saymaad
AppGini Super Hero
AppGini Super Hero
Posts:131
Joined: 2024-06-03 16:17

Re: Add button on table view page

Post by saymaad » 2025-07-12 04:32

Hello Elgaucho,

table_init filter is server-side and enforced before any client-side filters from JavaScript are applied. So when a user click this custom button, the JavaScript changes the URL parameters, but the table_init filter still filters out Completed records on the server, regardless of what the client asks.

That means any records excluded by table_init will never even reach the client, so the JavaScript filter can’t “re-include” them.

There are two ways to handle this which I suggest:

Option 1: Use a session or URL flag to conditionally skip table_init filter
You can modify table_init to check for a flag (in URL or session) and apply the filter only when desired:

Code: Select all

function companies_init(&$options, $memberInfo, &$args) {
  // Only apply the filter unless a flag is set
  if (!$_GET['no_default_filter']) {
    addFilter(1, 'and', 4, 'not-equal-to', 'Completed');
  }

  return TRUE;
}
Then, in your companies-tv.php, just add that flag to the URL:

Code: Select all

window.location = 'companies_view.php?' +
  "FilterField[1]=4" +
  "&FilterOperator[1]=equal-to" +
  "&FilterValue[1]=Pending Team A" +
  "&no_default_filter=1";

Option 2: Move the default filter logic to JavaScript instead of table_init
If the default filter is only for convenience (not for security), you could remove the table_init filter and instead auto-apply a default filter in JavaScript when no other filters are present.

This lets your filter buttons work normally, and you keep the "default view" behavior via JavaScript:

Code: Select all

$j(function () {
  if (!window.location.search.includes('FilterField')) {
    window.location = 'Companies_view.php?' +
      "FilterField[1]=4" +
      "&FilterOperator[1]=not-equal-to" +
      "&FilterValue[1]=Completed";
  }
});
PS: This is untested code, just to give you an idea on how to proceed, may need tweaking for live environment.

Post Reply