Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
add button to clear column filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromedockes committed Jun 28, 2024
1 parent 540f640 commit fdcc76e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/skrubview/_data/templates/column-filters.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<script type="text/javascript">
var columnFiltersForReport{{ report_id }} = JSON.parse('{{ column_filters | tojson | safe }}');
var columnFiltersForReport{{ report_id }} = JSON.parse('{{ column_filters | tojson | safe }}');
</script>

{% set col_filter_id = "{}_col_filter".format(report_id) %}

<div class="skrubview-wrapper">
<label for="{{ col_filter_id }}">Show: </label>
<select id="{{ col_filter_id }}" onchange='onFilterChange("{{ col_filter_id }}")' data-report-id="{{ report_id }}" autocomplete="off">
<select id="{{ col_filter_id }}" class="skrubview-col-filter-select"
onchange='onFilterChange("{{ col_filter_id }}")'
data-report-id="{{ report_id }}" autocomplete="off">
{% for filter_name in column_filters %}
<option value="{{ filter_name }}" {{ "selected" if filter_name == "all()" }}>{{ column_filters[filter_name]["display_name"] }}</option>
<option value="{{ filter_name }}" {{ "selected" if filter_name == "all()" }}>
{{ column_filters[filter_name]["display_name"] }}</option>
{% endfor %}
</select>
</div>
7 changes: 6 additions & 1 deletion src/skrubview/_data/templates/no-filter-matches.html
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
No columns match the selected filter: <strong class="skrubview-selected-filter-display"></strong>. Change the column filter in the dropdown menu above to display some columns.
<p>
No columns match the selected filter: <strong class="skrubview-selected-filter-display"></strong>. You can change the column filter in the dropdown menu above.
</p>
<p>
<button onclick="clearColFilter(event)">Show all columns</button>.
</p>
9 changes: 8 additions & 1 deletion src/skrubview/_data/templates/skrubview.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function onFilterChange(colFilterId) {
} else {
elem.dataset.isExcludedByFilter = "";
}
})
});
document.getElementById(`${reportId}_display_n_columns`).textContent = acceptedCols
.length.toString();
const tableElem = reportElem.querySelector(".skrubview-dataframe-sample-table");
Expand All @@ -250,3 +250,10 @@ function onFilterChange(colFilterId) {
filterDisplay.textContent = '"' + colFilters[filterName]["display_name"] + '"';
}
}

function clearColFilter(event){
const reportElem = event.target.closest(".skrubview-report");
const selectElem = reportElem.querySelector(".skrubview-col-filter-select");
selectElem.value = "all()";
onFilterChange(selectElem.id);
}

0 comments on commit fdcc76e

Please sign in to comment.