dropdown grid column, tiny style adjustment

This commit is contained in:
2023-04-03 23:58:53 +08:00
parent cb3b03f365
commit 3c1cbdf22e
3 changed files with 75 additions and 19 deletions

View File

@ -57,38 +57,65 @@ const SymbolDropdown = Symbol.for('ui-dropdown');
class GridDropdownColumn extends GridColumn {
static createEdit(trigger) {
const drop = new Dropdown({
});
const drop = new Dropdown();
drop.onselected = trigger;
return drop.create();
}
static setValue(element, val, item, col) {
static getDrop(element) {
const dropGlobal = global[SymbolDropdown];
if (dropGlobal == null) {
return;
return null;
}
const dropId = element.dataset.dropId;
const drop = dropGlobal[dropId];
if (drop == null) {
return;
return null;
}
return drop;
}
static getSource(item, col) {
let source = col.source;
if (typeof source === 'function') {
source = source(item);
}
if (source != null) {
drop.source = source;
return source;
}
static setValue(element, val, item, col) {
if (element.tagName !== 'DIV') {
let source = this.getSource(item, col);
const data = source?.find(v => v.value === val);
if (data != null) {
val = data.text;
}
super.setValue(element, val);
return;
}
const drop = this.getDrop(element);
if (drop == null) {
return;
}
if (drop.source == null || drop.source.length === 0) {
let source = this.getSource(item, col);
if (source != null) {
drop.source = source;
}
}
drop.select(val, true);
}
static getValue(e) {
return e.value;
}
static setEnabled(element, enabled) {
const drop = this.getDrop(element);
if (drop == null) {
return;
}
drop.disabled = enabled === false;
}
}
@ -596,6 +623,14 @@ class Grid {
if (!this.holderDisabled) {
const holder = document.createElement('div');
holder.className = 'grid-hover-holder';
holder.addEventListener('mousedown', e => {
const keyid = e.currentTarget.keyid;
if (keyid == null) {
return;
}
return this.#onRowClicked(e, (keyid >>> MaxColumnBit) - this.#startIndex, keyid & MaxColumnMask);
});
holder.addEventListener('dblclick', e => this.#onRowDblClicked(e));
bodyContainer.appendChild(holder);
body.addEventListener('mousemove', e => throttle(this.#onBodyMouseMove, RefreshInterval, this, e, holder));
}
@ -737,7 +772,7 @@ class Grid {
}
// auto resize
if (this.#needResize && col.autoResize) {
const width = cell.scrollWidth + 12;
const width = element.scrollWidth + 12;
if (width > 0 && widths != null && (isNaN(widths[j]) || widths[j] < width)) {
widths[j] = width;
widths.flag = true;
@ -923,14 +958,18 @@ class Grid {
if (keyid === oldkeyid) {
return;
}
const element = target.children[0];
if (element.tagName !== 'SPAN') {
return;
}
let overflow = this.#overflows[keyid];
if (overflow == null) {
overflow = target.scrollWidth > target.offsetWidth;
overflow = element.scrollWidth > element.offsetWidth;
this.#overflows[keyid] = overflow;
}
if (overflow) {
holder.keyid = keyid;
holder.innerText = target.innerText;
holder.innerText = element.innerText;
const top = this.#refs.bodyContent.offsetTop + target.offsetTop + 1;
let left = target.offsetLeft;
let width = holder.offsetWidth;