primevue-mirror/components/lib/datatable/RowCheckbox.vue

75 lines
2.4 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2024-01-14 14:09:03 +00:00
<Checkbox :modelValue="checked" :binary="true" :disabled="$attrs.disabled" :aria-label="checkboxAriaLabel" @change="onChange" :unstyled="unstyled" :pt="getColumnPT('rowCheckbox')">
2024-01-14 13:38:51 +00:00
<template #icon="slotProps">
<component v-if="rowCheckboxIconTemplate" :is="rowCheckboxIconTemplate" :checked="slotProps.checked" :class="slotProps.class" />
<CheckIcon v-else-if="!rowCheckboxIconTemplate && slotProps.checked" :class="slotProps.class" v-bind="getColumnPT('rowCheckbox.icon')" />
</template>
</Checkbox>
2022-09-06 12:03:37 +00:00
</template>
<script>
2023-05-08 14:08:06 +00:00
import BaseComponent from 'primevue/basecomponent';
2024-01-14 13:38:51 +00:00
import Checkbox from 'primevue/checkbox';
import CheckIcon from 'primevue/icons/check';
import { mergeProps } from 'vue';
2022-12-08 11:04:25 +00:00
2022-09-06 12:03:37 +00:00
export default {
name: 'RowCheckbox',
hostName: 'DataTable',
2023-05-08 14:08:06 +00:00
extends: BaseComponent,
2022-09-06 12:03:37 +00:00
emits: ['change'],
props: {
2022-09-14 11:26:01 +00:00
value: null,
checked: null,
column: null,
rowCheckboxIconTemplate: {
type: Function,
default: null
},
index: {
type: Number,
default: null
}
2022-09-06 12:03:37 +00:00
},
methods: {
getColumnPT(key) {
const columnMetaData = {
props: this.column.props,
parent: {
instance: this,
props: this.$props,
state: this.$data
},
2023-05-08 14:08:06 +00:00
context: {
index: this.index,
2023-05-08 14:08:06 +00:00
checked: this.checked,
disabled: this.$attrs.disabled
}
};
return mergeProps(this.ptm(`column.${key}`, { column: columnMetaData }), this.ptm(`column.${key}`, columnMetaData), this.ptmo(this.getColumnProp(), key, columnMetaData));
2023-05-08 14:08:06 +00:00
},
getColumnProp() {
return this.column.props && this.column.props.pt ? this.column.props.pt : undefined; //@todo:
},
2024-01-14 13:38:51 +00:00
onChange(event) {
2022-09-06 12:03:37 +00:00
if (!this.$attrs.disabled) {
this.$emit('change', {
originalEvent: event,
data: this.value
});
2022-12-08 11:04:25 +00:00
}
}
},
computed: {
checkboxAriaLabel() {
return this.$primevue.config.locale.aria ? (this.checked ? this.$primevue.config.locale.aria.selectRow : this.$primevue.config.locale.aria.unselectRow) : undefined;
2022-09-06 12:03:37 +00:00
}
},
components: {
2024-01-14 13:38:51 +00:00
CheckIcon,
Checkbox
2022-09-06 12:03:37 +00:00
}
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
</script>