Skip to content
This repository was archived by the owner on Apr 1, 2022. It is now read-only.

Possibility to pass a function as title or label. #81

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 3 additions & 2 deletions src/HeaderSettings/ColumnGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@
:disabled="typeof col.visible === 'string'"
@change="handleChange(col, $event.target.checked)">
<label :for="uuidGen(col.field || idx)">
{{ col.label || col.title }}
{{ renderTitleOrLabel(col) }}
<i v-if="col.explain" class="fa fa-info-circle" style="cursor: help" :title="col.explain"></i>
</label>
</li>
</ul>
</template>
<script>
import isColVisible from '../_utils/isColVisible'

import renderText from '../_mixins/renderText'
export default {
name: 'ColumnGroup',
mixins: [renderText],
props: {
groupName: { type: String, required: true },
columns: { type: Array, required: true }
Expand Down
5 changes: 3 additions & 2 deletions src/Table/TableHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
v-bind="$props">
</component>
<template v-else>
{{ col.title }}
{{renderTitle(col)}}
</template>

<i v-if="col.explain" class="fa fa-info-circle" style="cursor: help" :title="col.explain"></i>
Expand All @@ -30,11 +30,12 @@
import HeadSort from './HeadSort.vue'
import MultiSelect from './MultiSelect.vue'
import props from '../_mixins/props'
import renderText from '../_mixins/renderText'
import shouldRenderSelection from '../_mixins/shouldRenderSelection'

export default {
name: 'TableHeader',
components: { HeadSort, MultiSelect },
mixins: [props, shouldRenderSelection]
mixins: [props, shouldRenderSelection,renderText],
}
</script>
20 changes: 20 additions & 0 deletions src/_mixins/renderText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
methods:{
renderTitleOrLabel(col)
{
return this.getTitle(col) || this.getLabel();
},
renderTitle(col)
{
return this.getTitle(col);
},
getTitle(col)
{
return typeof(col.title) === 'function' ? col.title.apply() : col.title;
},
getLabel(col)
{
return typeof(col.label) === 'function' ? col.label.apply() : col.label;
}
}
}