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 all 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
46 changes: 44 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 @@ -37,11 +41,17 @@
{{props.formattedRow[props.column.field]}}
</span>
</template> -->

<template v-slot:table-actions-dropdown="{columns}">
Copy link
Collaborator Author

@p0psicles p0psicles Mar 9, 2021

Choose a reason for hiding this comment

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

Three lines to utilize the column filter, but a user can drop-in his own component if he likes.

<vgt-column-dropdown :columns="columns" />
</template>
</vue-good-table>
</div>
</template>

<script>
import VgtColumnDropdown from '../src/components/plugins/VgtColumnDropdown.vue';

export default {
name: 'grouped-table',
props: [],
Expand All @@ -54,6 +64,7 @@ export default {
filterOptions: {
enabled: true,
},
hidden: false,
},
{
label: 'Diet',
Expand All @@ -66,6 +77,7 @@ export default {
field: 'count',
headerField: this.sumCount,
type: 'number',
hidden: false,
},
],
rows: [
Expand Down Expand Up @@ -135,12 +147,42 @@ export default {
mounted() {
},
components: {
VgtColumnDropdown
},
};
</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>
26 changes: 14 additions & 12 deletions src/components/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@
: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">
</slot>
</template>
</vgt-global-search>
<div>
<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" :columns="columns"></slot>
</div>
<div
v-if="selectedRowCount && !disableSelectInfo"
class="vgt-selection-info-row clearfix"
Expand Down Expand Up @@ -1631,6 +1632,7 @@ export default {
this.clearSelectionText = clearSelectionText;
}
},

},

mounted() {
Expand Down
53 changes: 53 additions & 0 deletions src/components/plugins/VgtColumnDropdown.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<template>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@xaksis I think this is the best we can do to separate features from the core functionality.
My idea was to create a plugins folder, and add some "example" components there, and expose these to the user.
We could create cookbook section in de docs, that explains this.

Imo I think we should gradually move some of the components to the plugins folder. So the user can use those, extend from it. Or drop in something entirely different.

If you want to move to something that's for ex renderless, that's possible. But that would require a total rewrite. And imo I think Vue3's composition API could shine there. Abstracting out render related functions.

I think you can decrease maintenance costs, by utilizing scoped slots more, and having some example components in plugins. That way, you could put the MVP in plugins, while offering a lot of flexibility to the user.

<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
}
},
mounted() {
const { parentProps } = this;
console.log(parentProps);
},
methods: {
updateFilteredColumn(label, checked) {
this.columns.find(column => column.label === label).hidden = !checked;
}
},
watch: {
columns: {
handler() {
const { columns } = this;
this.filteredColumns = columns.filter(column => column.hidden !== undefined);
},
deep: true,
immediate: true,
},
}
};
</script>

<style>
</style>
Loading