Issue Feature Accepted

#106333TCA-Table: Functionality to add custom filter to the table

Jason Christian 03/07/25, 12:21 updated 11/14/26, 15:31

Description

Hi,

I don’t know whether I’ve missed something but I have checked the documentation in https://docs.typo3.org/m/typo3/reference-tca/12.4/en-us/Ctrl/Index.html and seen nothing about building custom filter for a TCA-Table. I’ve checked the documentation for `ctrl` and `columns`, but nothing about adding filter to the table (only for form). If there is already a way, kindly point me in the right direction

TYPO3 version = v12.4.26

Suppose I have a SQL-Table with column `verified` (TINYINT. Value is either 1 or 0), I would like to be able to filter the entries in the TCA-Table of said SQL-Table by `verified` column (e.g. as Checkbox or Select field on the table header). Currently I can only filter by text through the main filter, but I also want to filter by non-text columns

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

Fix this issue

Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". How to create a patch

Commit message
[FEATURE] TCA-Table: Functionality to add custom filter to the table Resolves: #106333 Releases: main

History 14

  1. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-03-10T09:05:55+00:00" > 03/10/25, 09:05 </span>

    Sadly I know of no extension which integrates this to the “normal” record list, but technically it should be possible, so maybe digging for something like that in the extension repository could be fruitful?

    The “DB Check” -> “Full search” backend module of EXT:lowlevel allows do define very specific filter rules to find record lists and save these as presets. However that might be a bit complex for editors.

    There is a PSR-14 Event ModifyDatabaseQueryForRecordListingEvent (see https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Feature-98490-PSR-14EventToAlterTheRecordsRenderedInRecordListings.html) that you can use to conditionally add more WHERE conditions to your record list, by evaluating the table name. Then however you will never be able to edit/view rows that have ‘verfied’ not set, so that might not be what you’re actually looking for?

  2. Garvin Hicking commented and changed status New Accepted <span data-processor="relativetime" data-value="2025-03-10T12:32:44+00:00" > 03/10/25, 12:32 </span>

    I’ve conferred with Oli Bartsch and Georg Ringer. We all believe this would be something that is desirable. I was made aware of https://github.com/TYPO3GmbH/querybuilder which provided such a feature in earlier versions. I do think we would need to put a lot of thinking into this feature and what it should provide in which way (with our without presets? Presets managed by editors or only integrators?). This all has a larger impact on the UI and UX. And it needs to be well-maintainable if it becomes part of the TYPO3 core.

    Personally, I’ve missed this a couple of times too, but usually provided custom backend modules then (using `<f:be>` in a custom module).</f:be>

    Thanks for bringing this up here, and let’s see if it gains traction! This wouldn’t be a small feature to implement, so it would take effort.

  3. Jason Christian commented <span data-processor="relativetime" data-value="2025-03-10T13:00:09+00:00" > 03/10/25, 13:00 </span>

    Thank your for confirming as well. My idea is that we can add it in TCA settings to make it easier for editors to implement them

    Somewhere along in

    $GLOBALS['TCA'][<tablename>]['columns'][<colname>]['tablefilter']
    [
      'type' => 'checkbox', # mapped to 1 or 0. WHERE verified = 0|1
      'label' => 'Verified'
    ]
    ...
    [
      'type' => 'select',
      'label' => 'Type',
      'options' => [ ['Type 1', 'type_1'], ['Type 2', 'type_2'], .... ] # or we can emit the `options` and it will be populated with all possible values from DB for that column
    ]
    ...
    [
      'type' => 'text',
      'label' => 'Search Term',
    ]

    In DatabaseRecordList.php probably the simplest way is to obtain these filter configurations, build HTML representations of it, and put it in `getTable()` as a new form. I am looking at RecordSearchBox to see how they can filter by text, but I haven’t found the exact query builder code for it.

  4. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-03-14T15:39:10+00:00" > 03/14/25, 15:39 </span>

    That sounds interesting! I am not too sure we should enhance the TCA for this kind of filters. Instead, something along how the RichttextEditor is configured might be better. So have a seperate place where to define filters.

    I actually believe setting this with TypoScript (and not a seperate YAML file or so) would be beneficial. This way, Page and User TS Config could be created to individually apply filters both to usergroups, single users, and also even make specific filters available to specific pages.

    So then you could do nice stuff like this:

    • In SysFolder A you setup News records and you allow filtering by title and category, very plain
    • In SysFolder B you could setup another filter that applies to the same News model (different records though) and you could filter those by different criteria, like an author start/enddate

    Since the FormEngine display of records is bound to the page tree, both evaluating TS config and Page TS config should fall into place quite nicely.

    What do you think?

  5. Jason Christian commented <span data-processor="relativetime" data-value="2025-03-17T09:06:11+00:00" > 03/17/25, 09:06 </span>

    > That sounds interesting! I am not too sure we should enhance the TCA for this kind of filters. Instead, something along how the RichttextEditor is configured might be better. So have a seperate place where to define filters.

    Do you mean the main filter RecordSearchBox where I can only enter text filter? That sounds good as well. I’m not very well-versed in TYPO3 yet so I have to check them first. By TSConfig, you mean in Configuration/TypoScript/setup.typoscript, right? I’m not so sure about permission-specific filters as well

    So something along this?

    plugin.tx_myextension {
       ...
       tca_filter {
          10 {
             column = verified
             type = select
             options {
                1 = All
                2 = 1, Verified
                3 = 0, Not Verified
             }
          ...
          }
       }
    }
  6. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-03-17T09:24:05+00:00" > 03/17/25, 09:24 </span>

    > Do you mean the main filter RecordSearchBox where I can only enter text filter?

    Honestly, I’m not sure yet how to do this with the UI. Probably next to that recordSearchBox one would need a box I can check like “apply filtering” or choose existing filters? Like the old EXT:querybuilder did this, but the UI there is a bit clunky. If there’s an easy way like only a dropdown to pick an existing filter (configured via the TSconfig) that would be less intrusive.

    And yes, I mean setup.typoscript with this – if it’s entered in that file it becomes “Page TSconfig”. You could use the same syntax though for user specific TSconfig which can be conditionally applied: https://docs.typo3.org/m/typo3/reference-typoscript/main/en-us/UsingSettingTSconfig/UserTSconfig.html

    > So something along this?

    I would do that more with a top-level configuration like:

    # The main global key
    page.tcaFilters {
       # subkey: tablename 
       tt_content {
    
       }
    
       # subkey: tablename
       tx_myextension_domain_model_mypage {
         10 {
             column = verified
             type = select
             options {
                10 {
                  label = All
                  sqlWhere = ' and {#tx_myextension_domain_model_mypage}.verified IN (0,1)'
                }  
                20 {
                  label = Verified
                  sqlWhere = ' and {#tx_myextension_domain_model_mypage}.verified = 1'
                } 
                30 {
                  label = Not Verified
                  sqlWhere = ' and {#tx_myextension_domain_model_mypage}.verified = 0'
                }
                40 {
                  label = Complex
                  sqlWhere = ' and {#tx_myextension_domain_model_mypage}.verified = 1 and {#tx_myextension_domain_model_mypage}.category != "" and {#tx_myextension_domain_model_mypage}.is_highlight = 1'
                }
             }
          ...
       }
    }

    I’m not too happy of having inline SQL there. But doing a more complex field definition approach within TypoScript would be overkill.

  7. Jason Christian commented <span data-processor="relativetime" data-value="2025-03-17T10:38:59+00:00" > 03/17/25, 10:38 </span>

    > I’m not too happy of having inline SQL there. But doing a more complex field definition approach within TypoScript would be overkill.

    we can connect it to the extension controller/repository’s method if we need a more complex query, but I’m not sure if it can be done inside TSConfig

    # The main global key
    page.tcaFilters {
       # subkey: tablename 
       tt_content {
          ...
       }
    
       # subkey: tablename
       tx_myextension_domain_model_mypage {
         10 {
             # Through controller action
             type = select
             label = Verified
             action = EXT:myextension/Controller/MyExtensionController::queryByVerified
             options {
                10 {
                  label = All
                }  
                20 {
                  label = Verified
                } 
                30 {
                  label = Not Verified
                }
                40 {
                  label = Complex
                }
             }
    
         20 {
             # Standard SQL query (WHERE verified = 0|1)
             column = verified
             type = checkbox
             ...
            }
          ...
       }
    }
  8. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-03-17T15:18:38+00:00" > 03/17/25, 15:18 </span>

    My main goal here would be to make filter presets easily configurable by integrators (else we could use PSR14-events or userFuncs, similar to what you suggested).

    We’ll really need to figure out how to make filtering available both to integrators/developers but I guess we’ll need a GUI variant for casual editors too at some point. But maybe until that can be done well, having a workable filter as an extension or implementing “low hanging fruits” would be nice…!

  9. Georg Ringer changed Tags TCA, backend, table, filter TCA, backend, table, filter ux-decision <span data-processor="relativetime" data-value="2025-04-10T19:01:45+00:00" > 04/10/25, 19:01 </span>