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

TableColumn: Add 'disabled' prop to 'selection' type column #21448

Open
wants to merge 2 commits into
base: dev
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
6 changes: 3 additions & 3 deletions packages/table/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ export const cellStarts = {
// 这些选项不应该被覆盖
export const cellForced = {
selection: {
renderHeader: function(h, { store }) {
renderHeader: function(h, { store, column }) {
return <el-checkbox
disabled={ store.states.data && store.states.data.length === 0 }
disabled={ store.states.data && store.states.data.length === 0 || column.disabled }
indeterminate={ store.states.selection.length > 0 && !this.isAllSelected }
nativeOn-click={ this.toggleAllSelection }
nativeOn-click={ !column.disabled ? this.toggleAllSelection : ()=>{} }
value={ this.isAllSelected } />;
},
renderCell: function(h, { row, column, store, $index }) {
Expand Down
10 changes: 10 additions & 0 deletions packages/table/src/store/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export default Vue.extend({
if (oldSelection.length) {
states.selection = [];
this.table.$emit('selection-change', []);
states.unselection = [];
this.table.$emit('unselection-change', []);
}
},

Expand Down Expand Up @@ -165,6 +167,14 @@ export default Vue.extend({
}
this.table.$emit('selection-change', newSelection);
}
if (!this.isSelected(row)) {
if (!this.states.unselection) this.states.unselection = [];
this.states.unselection.push(row);
} else if (this.states.unselection) {
let indx = this.states.unselection.findIndex(v => v.ns_id === row.ns_id);
this.states.unselection.splice(indx, indx >= 0 ? 1 : 0);
}
if (this.states.unselection && this.states.unselection.length > 0) this.table.$emit('unselection-change', this.states.unselection);
},

_toggleAllSelection() {
Expand Down
11 changes: 8 additions & 3 deletions packages/table/src/table-column.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export default {
validator(val) {
return val.every(order => ['ascending', 'descending', null].indexOf(order) > -1);
}
},
disabled: {
type: Boolean,
default: false
}
},

Expand Down Expand Up @@ -195,13 +199,14 @@ export default {
},

registerNormalWatchers() {
const props = ['label', 'property', 'filters', 'filterMultiple', 'sortable', 'index', 'formatter', 'className', 'labelClassName', 'showOverflowTooltip'];
const props = ['label', 'property', 'filters', 'filterMultiple', 'sortable', 'index', 'formatter', 'className', 'labelClassName', 'showOverflowTooltip', 'disabled'];
// 一些属性具有别名
const aliases = {
prop: 'property',
realAlign: 'align',
realHeaderAlign: 'headerAlign',
realWidth: 'width'
realWidth: 'width',
disabled: 'disabled'
};
const allAliases = props.reduce((prev, cur) => {
prev[cur] = cur;
Expand Down Expand Up @@ -280,7 +285,7 @@ export default {

const basicProps = ['columnKey', 'label', 'className', 'labelClassName', 'type', 'renderHeader', 'formatter', 'fixed', 'resizable'];
const sortProps = ['sortMethod', 'sortBy', 'sortOrders'];
const selectProps = ['selectable', 'reserveSelection'];
const selectProps = ['selectable', 'reserveSelection', 'disabled'];
const filterProps = ['filterMethod', 'filters', 'filterMultiple', 'filterOpened', 'filteredValue', 'filterPlacement'];

let column = this.getPropsData(basicProps, sortProps, selectProps, filterProps);
Expand Down