Set filter stack from module on a table outside of that module

I have an app that has a table and currently has filtering controlled by a text input and a select.
The filters logically are

(column1 includes value or column2 includes value or column3 includes value) and column4 includes value.

Both the text input and the select set the filters for a table, currently called table1, as follows.

[
  {
    operator: "or",
    filters: [
      { columnId: "column1", operator: "includes", value: {{search_input.value}} },
      { columnId: "column2", operator: "includes", value: {{search_input.value}} },
      { columnId: "column3", operator: "includes", value: {{search_input.value}} }
    ]
  },
  {
    operator: "and",
    filters: [
      { columnId: "column4", operator: "includes", value: {{b_selector.selectedItem}} }
    ]
  }
]

This works for my current table but I would like to make this search functionality into a module so that I can apply it to many tables. The issue right now is that I do not know how to tell the event handler in the module which table is being referenced.

I have tried making a script to apply the filters instead like so

table1.setFilterStack( {
    operator: "or",
    filters: [
      { columnId: "column1", operator: "includes", value: search_input.value },
      { columnId: "column2", operator: "includes", value: search_input.value },
      { columnId: "column3", operator: "includes", value: search_input.value }
    ]
  },{
    operator: "and",
    filters: [
      { columnId: "column4", operator: "includes", value: b_selector.selectedItem }
    ]
  });

and then passing that in as a query param to the module, but with the above code only the first set of ors get set and the second stack is ignored.

is there a better way to tell the module which table to apply the filters to? I am open to a different approach as long as the filtering works and I can modularize it if possible.

EDIT: After seeing the post on dynamic table columns I tried that as well. That very nearly works for my case but then I lose the formatting of my data (like images show as urls and money values are not currencies) and as far as I can tell I cant set that for the dynamic columns

Hey @James_Tuxbury, turning the search functionality into a reusable module sounds like a good idea. Would you be able to export your module so we can test it on our end with some tables to see what changes need to be made to possibly get this up and running?

If you could export your parent app as well so we can see how they work together would be great