2016-10-26 03:58:35 +00:00
|
|
|
<template>
|
2016-10-27 06:48:13 +00:00
|
|
|
<tr class="md-table-row" :class="classes" @click.stop="autoSelect">
|
2016-10-27 05:52:58 +00:00
|
|
|
<md-table-cell class="md-table-selection" v-if="$parent.mdRowSelection">
|
2016-10-26 03:58:35 +00:00
|
|
|
<md-checkbox v-model="checkbox" @change="select"></md-checkbox>
|
2016-10-27 05:52:58 +00:00
|
|
|
</md-table-cell>
|
2016-10-26 03:58:35 +00:00
|
|
|
|
|
|
|
|
<slot></slot>
|
|
|
|
|
</tr>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2016-10-26 23:59:51 +00:00
|
|
|
const transitionClass = 'md-transition-off';
|
|
|
|
|
|
2016-10-26 03:58:35 +00:00
|
|
|
export default {
|
2016-10-27 06:48:13 +00:00
|
|
|
props: {
|
|
|
|
|
mdAutoSelect: Boolean
|
|
|
|
|
},
|
2016-10-26 03:58:35 +00:00
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
checkbox: false,
|
|
|
|
|
index: 0
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
classes() {
|
|
|
|
|
return {
|
|
|
|
|
'md-selected': this.checkbox
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
setSelectedRow(value, index) {
|
|
|
|
|
if (value) {
|
2016-10-26 23:59:51 +00:00
|
|
|
this.$parent.selectedRows[index] = value;
|
|
|
|
|
++this.$parent.numberOfSelected;
|
|
|
|
|
} else {
|
|
|
|
|
delete this.$parent.selectedRows[index];
|
|
|
|
|
--this.$parent.numberOfSelected;
|
2016-10-26 03:58:35 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
handleSingleSelection(value) {
|
|
|
|
|
this.setSelectedRow(value, this.index);
|
2016-10-27 05:52:58 +00:00
|
|
|
this.$parent.$children[0].checkbox = this.$parent.numberOfSelected === this.$parent.numberOfRows;
|
2016-10-26 03:58:35 +00:00
|
|
|
},
|
|
|
|
|
handleMultipleSelection(value) {
|
2016-10-27 05:52:58 +00:00
|
|
|
if (this.$parent.numberOfRows > 25) {
|
|
|
|
|
this.$parent.$el.classList.add(transitionClass);
|
|
|
|
|
}
|
2016-10-26 23:59:51 +00:00
|
|
|
|
|
|
|
|
this.$parent.$children.forEach((row) => {
|
2016-10-26 03:58:35 +00:00
|
|
|
row.checkbox = value;
|
|
|
|
|
});
|
2016-10-26 23:59:51 +00:00
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
|
/*this.$parent.selectedRows = {}; //and so on, this can be lazly created the first time or on component boot*/
|
|
|
|
|
this.$parent.numberOfSelected = this.$parent.numberOfRows;
|
|
|
|
|
} else {
|
|
|
|
|
/*this.$parent.selectedRows = {};*/
|
|
|
|
|
this.$parent.numberOfSelected = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.setTimeout(() => this.$parent.$el.classList.remove(transitionClass));
|
2016-10-26 03:58:35 +00:00
|
|
|
},
|
|
|
|
|
select(value) {
|
|
|
|
|
if (this.$parent.mdRowSelection) {
|
|
|
|
|
if (this.headRow) {
|
|
|
|
|
this.handleMultipleSelection(value);
|
|
|
|
|
} else {
|
|
|
|
|
this.handleSingleSelection(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-27 06:48:13 +00:00
|
|
|
},
|
|
|
|
|
autoSelect() {
|
|
|
|
|
if (this.mdAutoSelect) {
|
|
|
|
|
this.checkbox = !this.checkbox;
|
|
|
|
|
this.handleSingleSelection(this.checkbox);
|
|
|
|
|
}
|
2016-10-26 03:58:35 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
if (this.$el.parentNode.tagName.toLowerCase() === 'thead') {
|
|
|
|
|
this.headRow = true;
|
|
|
|
|
} else {
|
|
|
|
|
this.$parent.numberOfRows++;
|
|
|
|
|
this.index = this.$parent.numberOfRows;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|