Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add column filters component #821

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions dev/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default {
// filterDropdownItems: ['Chris', 'Dan', 'Susan'],
// filterValue: 'Chris',
},
hidden: false,
},
{
label: 'Age',
Expand All @@ -93,6 +94,7 @@ export default {
// },
// ],
},
hidden: false,
},
{
filterOptions: {
Expand All @@ -104,16 +106,19 @@ export default {
type: 'date',
dateInputFormat: 'yyyy-MM-dd',
dateOutputFormat: 'PPPP',
hidden: false,
},
{
label: 'Percent',
field: 'score',
type: 'percentage',
hidden: false,
},
{
label: 'func',
field: this.funcValue,
type: 'number',
hidden: false,
},
{
label: 'Valid',
Expand All @@ -126,6 +131,7 @@ export default {
false,
],
},
hidden: false,
},
{
label: 'Exact',
Expand All @@ -137,6 +143,7 @@ export default {
'rematch',
],
},
hidden: false,
}
],
rows: [
Expand Down
39 changes: 37 additions & 2 deletions dev/grouped-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<button @click="expandAll">Expand All</button>
<button @click="collapseAll">Collapse All</button>
<vue-good-table
id="vgt-root"
:columns="columns"
:rows="rows"
:line-numbers="true"
Expand All @@ -28,6 +29,9 @@
}"
styleClass="vgt-table condensed bordered"
ref="groupedTable"
:column-filter-options="{
enabled: true
}"
>
<!-- <template slot="table-header-row" slot-scope="props">
<span v-if="props.row.mode === 'span'">
Expand All @@ -54,6 +58,7 @@ export default {
filterOptions: {
enabled: true,
},
hidden: false,
},
{
label: 'Diet',
Expand All @@ -66,6 +71,7 @@ export default {
field: 'count',
headerField: this.sumCount,
type: 'number',
hidden: false,
},
],
rows: [
Expand Down Expand Up @@ -140,7 +146,36 @@ export default {
</script>

<style lang="scss" scoped>
.row-style{
background-color: red;
.row-style {
background-color: red;
}

#vgt-root >>> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried applying a little example styling. But it won't work.
I'm not used to using scss, so maybe I foobar'd there?

.vgt-dropdown {
float: right;
margin-bottom: 5px;
}

ul.vgt-dropdown-menu {
position: absolute;
float: left;
min-width: 160px;
padding: 5px 0;
margin: 2px 0 0;
font-size: 14px;
text-align: left;
list-style: none;
background-clip: padding-box;
border-radius: 4px;

li > span {
display: block;
padding: 3px 20px;
clear: both;
font-weight: 400;
line-height: 1.42857143;
white-space: nowrap;
}
}
}
</style>
58 changes: 47 additions & 11 deletions src/components/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,21 @@
:info-fn="paginationInfoFn"
></vgt-pagination>
</slot>
<vgt-global-search
@on-keyup="searchTableOnKeyUp"
@on-enter="searchTableOnEnter"
v-model="globalSearchTerm"
:search-enabled="searchEnabled && externalSearchQuery == null"
:global-search-placeholder="searchPlaceholder"
>
<template slot="internal-table-actions">
<slot name="table-actions">
<div slot="table-actions">
<slot name="table-actions-header"></slot>
<slot name="table-actions-global-search">
<vgt-global-search
@on-keyup="searchTableOnKeyUp"
@on-enter="searchTableOnEnter"
v-model="globalSearchTerm"
:search-enabled="searchEnabled && externalSearchQuery == null"
:global-search-placeholder="searchPlaceholder"
/>
</slot>
<slot name="table-actions-dropdown">
<vgt-column-dropdown v-if="columnFilterEnabled" :columns="columns" @input="toggleFilteredColumn"/>
</slot>
</template>
</vgt-global-search>
</div>
<div
v-if="selectedRowCount && !disableSelectInfo"
class="vgt-selection-info-row clearfix"
Expand Down Expand Up @@ -346,6 +349,7 @@ import VgtPagination from './pagination/VgtPagination.vue';
import VgtGlobalSearch from './VgtGlobalSearch.vue';
import VgtTableHeader from './VgtTableHeader.vue';
import VgtHeaderRow from './VgtHeaderRow.vue';
import VgtColumnDropdown from './VgtColumnDropdown.vue';

// here we load each data type module.
import * as CoreDataTypes from './types/index';
Expand Down Expand Up @@ -436,6 +440,14 @@ export default {
};
},
},

columnFilterOptions: {
default() {
return {
enabled: false,
};
},
},
},

data: () => ({
Expand Down Expand Up @@ -494,6 +506,9 @@ export default {
forceSearch: false,
sortChanged: false,
dataTypes: dataTypes || {},

// internal column filter options
columnFilterEnabled: false,
}),

watch: {
Expand Down Expand Up @@ -556,6 +571,14 @@ export default {
});
}
},

columnFilterOptions: {
handler() {
this.initializeColumnFilter();
},
deep: true,
immediate: true,
},
},

computed: {
Expand Down Expand Up @@ -1439,6 +1462,10 @@ export default {
return originalRows;
},

toggleFilteredColumn(value) {
this.columns.find(column => column.label === value.label).hidden = !value.checked;
},

initializePagination() {
const {
enabled,
Expand Down Expand Up @@ -1631,6 +1658,14 @@ export default {
this.clearSelectionText = clearSelectionText;
}
},

initializeColumnFilter() {
const { enabled } = this.columnFilterOptions;

if (typeof enabled === 'boolean') {
this.columnFilterEnabled = enabled;
}
},
},

mounted() {
Expand All @@ -1645,6 +1680,7 @@ export default {
'vgt-global-search': VgtGlobalSearch,
'vgt-header-row': VgtHeaderRow,
'vgt-table-header': VgtTableHeader,
'vgt-column-dropdown': VgtColumnDropdown,
},
};
</script>
Expand Down
49 changes: 49 additions & 0 deletions src/components/VgtColumnDropdown.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div class="vgt-dropdown vgt-clearfix">
<!-- Drowdown with checkboxes for showing / hiding table headers -->
<div class="button-group pull-right">
<button type="button" class="btn btn-default btn-sm dropdown-toggle" @click="selectOpen = !selectOpen"><span class="fa fa-cog" aria-hidden="false">Select Columns</span> <span class="caret" /></button>
<ul v-show="selectOpen" class="vgt-dropdown-menu">
<li v-for="(column, index) in filteredColumns" :key="index">
<span class="small" tabIndex="-1">
<input :ref="`filterlabel${column.label}`" :checked="!column.hidden" @change.prevent="updateFilteredColumn(column.label, $event.target.checked)" type="checkbox">
{{column.label}}
</span>
</li>
</ul>
</div>
</div>
</template>

<script>
export default {
name: 'vgtColumnDropdown',
props: [
'columns',
],
data() {
return {
filteredColumns: [],
selectOpen: false
}
},
methods: {
updateFilteredColumn(columnLabel, checked) {
this.$emit('input', { label: columnLabel, checked });
}
},
watch: {
columns: {
handler() {
const { columns } = this;
this.filteredColumns = columns.filter(column => column.hidden !== undefined);
},
deep: true,
immediate: true,
},
}
};
</script>

<style>
</style>
Loading