diff --git a/datasette/templates/table.html b/datasette/templates/table.html
index 30162330..6deaaf1e 100644
--- a/datasette/templates/table.html
+++ b/datasette/templates/table.html
@@ -92,11 +92,11 @@
This data as .json
{% if suggested_facets %}
- Suggested facets: {% for facet in suggested_facets %}{{ facet.name }} {% endfor %}
+
Suggested facets: {% for facet in suggested_facets %}{{ facet.name }}{% if not loop.last %}, {% endif %}{% endfor %}
{% endif %}
{% for facet_name, facet_info in facet_results.items() %}
-
{{ facet_name }}
+ {{ facet_name }}
{% for facet_value in facet_info.results %}
- {{ facet_value.value }} ({{ facet_value.count }})
diff --git a/datasette/utils.py b/datasette/utils.py
index 2e2f5b5c..35950c68 100644
--- a/datasette/utils.py
+++ b/datasette/utils.py
@@ -166,10 +166,18 @@ def path_with_added_args(request, args, path=None):
def path_with_removed_args(request, args, path=None):
+ # args can be a dict or a set
path = path or request.path
current = []
+ if isinstance(args, set):
+ def should_remove(key, value):
+ return key in args
+ elif isinstance(args, dict):
+ # Must match key AND value
+ def should_remove(key, value):
+ return args.get(key) == value
for key, value in urllib.parse.parse_qsl(request.query_string):
- if key not in args:
+ if not should_remove(key, value):
current.append((key, value))
query_string = urllib.parse.urlencode(current)
if query_string:
diff --git a/datasette/views/table.py b/datasette/views/table.py
index a567d42c..b0e06ee1 100644
--- a/datasette/views/table.py
+++ b/datasette/views/table.py
@@ -658,6 +658,7 @@ class TableView(RowTableShared):
"display_rows": display_rows,
"is_sortable": any(c["sortable"] for c in display_columns),
"path_with_replaced_args": path_with_replaced_args,
+ "path_with_removed_args": path_with_removed_args,
"request": request,
"sort": sort,
"sort_desc": sort_desc,
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 99680fd6..73c40405 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -51,6 +51,7 @@ def test_path_with_added_args(path, added_args, expected):
@pytest.mark.parametrize('path,args,expected', [
('/foo?bar=1', {'bar'}, '/foo'),
('/foo?bar=1&baz=2', {'bar'}, '/foo?baz=2'),
+ ('/foo?bar=1&bar=2&bar=3', {'bar': '2'}, '/foo?bar=1&bar=3'),
])
def test_path_with_removed_args(path, args, expected):
request = Request(