# Show/hide a Browser column programmatically

**URL:** <https://forums.ankiweb.net/t/show-hide-a-browser-column-programmatically/48224>\
**Category:** Development\
**Created:** [August 14, 2024, 11:55pm UTC](https://forums.ankiweb.net/t/show-hide-a-browser-column-programmatically/48224 "2024-08-14T23:55:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleks\_ya](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/aleks_ya/32/22205_2.png) [@aleks\_ya](https://forums.ankiweb.net/u/aleks_ya)\
**Post date:** [August 14, 2024, 11:55pm UTC](https://forums.ankiweb.net/t/show-hide-a-browser-column-programmatically/48224/1 "2024-08-14T23:55:59Z")

</div>

[My addon](https://ankiweb.net/shared/info/1188705668) adds new columns into the Browser.  
I want to show the new columns after addon installation (then user can hide them if not needed).  
**What’s the proper way to show and hide a column from addon code?**

* * *

The only working approach I found is

- Show column: `browser.form.tableView.showColumn("Due")`
- Hide column: `browser.form.tableView.hideColumn("Due")`

But it uses `QTableView` functions directly without updating Anki models.

* * *

Partially working approach is using `Collection#set_browser_note_columns()` and `Collection#set_browser_card_columns()`. Then I need to refresh Browser table like in `Table#_on_column_toggled()`, which involves using many inner functions.

---

<div class="post-metadata">

**Author:** ![aleks\_ya](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/aleks_ya/32/22205_2.png) [@aleks\_ya](https://forums.ankiweb.net/u/aleks_ya)\
**Post date:** [August 15, 2024, 12:25am UTC](https://forums.ankiweb.net/t/show-hide-a-browser-column-programmatically/48224/2 "2024-08-15T00:25:39Z")

</div>

Found a better working approach, but it uses private property `Table#_model`:

```auto
from anki.collection import Collection
from aqt.browser import Browser, Table
from aqt.utils import show_info

__due_column: str = "cardDue"

def __on_show_due_column(browser: Browser):
    col: Collection = browser.col
    table: Table = browser.table
    if table.is_notes_mode():
        if __due_column not in col.load_browser_note_columns():
            table._model.toggle_column(__due_column)
    else:
        if __due_column not in col.load_browser_card_columns():
            table._model.toggle_column(__due_column)

def __on_hide_due_column(browser: Browser):
    col: Collection = browser.col
    table: Table = browser.table
    if table.is_notes_mode():
        if __due_column in col.load_browser_note_columns():
            table._model.toggle_column(__due_column)
    else:
        if __due_column in col.load_browser_card_columns():
            table._model.toggle_column(__due_column)

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [September 14, 2024, 7:12pm UTC](https://forums.ankiweb.net/t/show-hide-a-browser-column-programmatically/48224/4 "2024-09-14T19:12:28Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
