optimized
This commit is contained in:
parent
09bdef19d5
commit
6dc9df8b17
@ -986,7 +986,7 @@ export class Grid {
|
|||||||
* 获取或设置 Grid 是否为只读
|
* 获取或设置 Grid 是否为只读
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
get readonly() { return this._var.readonly }
|
get readonly() { return this._var.readonly === true }
|
||||||
set readonly(flag) {
|
set readonly(flag) {
|
||||||
this._var.readonly = flag;
|
this._var.readonly = flag;
|
||||||
this.refresh();
|
this.refresh();
|
||||||
@ -1283,9 +1283,7 @@ export class Grid {
|
|||||||
set selectedIndexes(indexes) {
|
set selectedIndexes(indexes) {
|
||||||
const startIndex = this._var.startIndex;
|
const startIndex = this._var.startIndex;
|
||||||
this._var.selectedIndexes.splice(0, this._var.selectedIndexes.length, ...indexes);
|
this._var.selectedIndexes.splice(0, this._var.selectedIndexes.length, ...indexes);
|
||||||
if (this.readonly !== true) {
|
if (this.readonly) {
|
||||||
this.refresh();
|
|
||||||
} else {
|
|
||||||
this._tableRows.forEach((row, i) => {
|
this._tableRows.forEach((row, i) => {
|
||||||
if (indexes.includes(startIndex + i)) {
|
if (indexes.includes(startIndex + i)) {
|
||||||
row.classList.add('selected');
|
row.classList.add('selected');
|
||||||
@ -1293,6 +1291,8 @@ export class Grid {
|
|||||||
row.classList.remove('selected');
|
row.classList.remove('selected');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.refresh();
|
||||||
}
|
}
|
||||||
if (typeof this.onSelectedRowChanged === 'function') {
|
if (typeof this.onSelectedRowChanged === 'function') {
|
||||||
this.onSelectedRowChanged();
|
this.onSelectedRowChanged();
|
||||||
@ -1393,12 +1393,12 @@ export class Grid {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
selectedIndexes.splice(0);
|
selectedIndexes.splice(0);
|
||||||
if (this.readonly !== true) {
|
if (this.readonly) {
|
||||||
this.refresh();
|
|
||||||
} else {
|
|
||||||
this._tableRows.forEach(row => {
|
this._tableRows.forEach(row => {
|
||||||
row.classList.remove('selected');
|
row.classList.remove('selected');
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.refresh();
|
||||||
}
|
}
|
||||||
if (typeof this.onSelectedRowChanged === 'function') {
|
if (typeof this.onSelectedRowChanged === 'function') {
|
||||||
this.onSelectedRowChanged(-1);
|
this.onSelectedRowChanged(-1);
|
||||||
@ -1929,6 +1929,7 @@ export class Grid {
|
|||||||
thead.appendChild(header);
|
thead.appendChild(header);
|
||||||
const sizer = this._var.refs.sizer;
|
const sizer = this._var.refs.sizer;
|
||||||
let left = this.expandable ? ExpandableWidth : 0;
|
let left = this.expandable ? ExpandableWidth : 0;
|
||||||
|
const readonly = this.readonly;
|
||||||
if (this.expandable) {
|
if (this.expandable) {
|
||||||
header.appendChild(createElement('th', th => {
|
header.appendChild(createElement('th', th => {
|
||||||
th.className = 'ui-expandable sticky';
|
th.className = 'ui-expandable sticky';
|
||||||
@ -1971,7 +1972,7 @@ export class Grid {
|
|||||||
this._var.needResize = true;
|
this._var.needResize = true;
|
||||||
sizer.innerText = col.caption ?? '';
|
sizer.innerText = col.caption ?? '';
|
||||||
let width = sizer.offsetWidth + 22;
|
let width = sizer.offsetWidth + 22;
|
||||||
if (!this.readonly && col.enabled !== false && col.allcheck && isCheckbox) {
|
if (!readonly && col.enabled !== false && col.allcheck && isCheckbox) {
|
||||||
width += 32;
|
width += 32;
|
||||||
}
|
}
|
||||||
if (col.allowFilter === true) {
|
if (col.allowFilter === true) {
|
||||||
@ -2024,7 +2025,7 @@ export class Grid {
|
|||||||
wrapper.style.justifyContent = 'center';
|
wrapper.style.justifyContent = 'center';
|
||||||
}
|
}
|
||||||
th.appendChild(wrapper);
|
th.appendChild(wrapper);
|
||||||
if (!this.readonly && col.enabled !== false && col.allcheck && isCheckbox) {
|
if (!readonly && col.enabled !== false && col.allcheck && isCheckbox) {
|
||||||
const check = createCheckbox({
|
const check = createCheckbox({
|
||||||
onchange: e => this._onColumnAllChecked(col, e.target.checked)
|
onchange: e => this._onColumnAllChecked(col, e.target.checked)
|
||||||
});
|
});
|
||||||
@ -2110,7 +2111,7 @@ export class Grid {
|
|||||||
const exists = content.querySelectorAll('&>.ui-grid-row').length;
|
const exists = content.querySelectorAll('&>.ui-grid-row').length;
|
||||||
count -= exists;
|
count -= exists;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
const readonly = this._var.readonly;
|
const readonly = this.readonly;
|
||||||
for (let i = 0; i < count; ++i) {
|
for (let i = 0; i < count; ++i) {
|
||||||
const row = createElement('tr', 'ui-grid-row');
|
const row = createElement('tr', 'ui-grid-row');
|
||||||
let left = this.expandable ? ExpandableWidth : 0;
|
let left = this.expandable ? ExpandableWidth : 0;
|
||||||
@ -2199,7 +2200,7 @@ export class Grid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const offset = this.expandable ? 1 : 0;
|
const offset = this.expandable ? 1 : 0;
|
||||||
const readonly = this._var.readonly;
|
const readonly = this.readonly;
|
||||||
[...rows].forEach((row, i) => {
|
[...rows].forEach((row, i) => {
|
||||||
const vals = this._var.currentSource[startIndex + i];
|
const vals = this._var.currentSource[startIndex + i];
|
||||||
if (vals == null) {
|
if (vals == null) {
|
||||||
@ -2323,7 +2324,7 @@ export class Grid {
|
|||||||
element = cell.children[0];
|
element = cell.children[0];
|
||||||
}
|
}
|
||||||
let enabled;
|
let enabled;
|
||||||
if (this.readonly) {
|
if (readonly) {
|
||||||
enabled = false;
|
enabled = false;
|
||||||
} else {
|
} else {
|
||||||
enabled = col.enabled;
|
enabled = col.enabled;
|
||||||
@ -3216,9 +3217,7 @@ export class Grid {
|
|||||||
}
|
}
|
||||||
// apply style
|
// apply style
|
||||||
if (flag) {
|
if (flag) {
|
||||||
if (this.readonly !== true) {
|
if (this.readonly) {
|
||||||
this.refresh();
|
|
||||||
} else {
|
|
||||||
this._tableRows.forEach((row, i) => {
|
this._tableRows.forEach((row, i) => {
|
||||||
if (selectedIndexes.includes(startIndex + i)) {
|
if (selectedIndexes.includes(startIndex + i)) {
|
||||||
row.classList.add('selected');
|
row.classList.add('selected');
|
||||||
@ -3226,6 +3225,8 @@ export class Grid {
|
|||||||
row.classList.remove('selected');
|
row.classList.remove('selected');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.refresh();
|
||||||
}
|
}
|
||||||
if (typeof this.onSelectedRowChanged === 'function') {
|
if (typeof this.onSelectedRowChanged === 'function') {
|
||||||
this.onSelectedRowChanged(selectedIndex);
|
this.onSelectedRowChanged(selectedIndex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user