Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function toHtml ($xetable, opts, columns, datas) {
const { id, border, treeConfig, treeOpts, isAllSelected, headerAlign: allHeaderAlign, align: allAlign, footerAlign: allFooterAlign, showOverflow: allShowOverflow, showAllOverflow: oldShowAllOverflow, showHeaderOverflow: allHeaderOverflow, showHeaderAllOverflow: oldHeaderOverflow } = $xetable
// v2.0 废弃属性,保留兼容
let allColumnOverflow = XEUtils.isBoolean(oldShowAllOverflow) ? oldShowAllOverflow : allShowOverflow
let allColumnHeaderOverflow = XEUtils.isBoolean(oldHeaderOverflow) ? oldHeaderOverflow : allHeaderOverflow
let clss = [
'vxe-table',
border ? 't--border' : '',
border === 'none' ? 'b--style-none' : '',
opts.print ? 'is--print' : '',
opts.isHeader ? 'show--head' : ''
].filter(cls => cls)
let html = [
'',
``,
`<title>${opts.sheetName}</title>`,
`<style>${opts.style || defaultHtmlStyle}</style>`,
'',
'',
``,<table cellpadding="0" cellspacing="0" border="0" class="${clss.join(' ')}"></table>
tableFullColumn.forEach(column => {
// 在 v3.0 中废弃 prop
let item = XEUtils.find(customColumns, item => column.property && (item.field || item.prop) === column.property)
if (item) {
if (XEUtils.isNumber(item.resizeWidth)) {
column.resizeWidth = item.resizeWidth
}
if (XEUtils.isBoolean(item.visible)) {
column.visible = item.visible
}
}
})
}
sortChangeEvent (params) {
let { proxyConfig, remoteSort } = this
let { $table, column } = params
let isRemote = XEUtils.isBoolean(column.remoteSort) ? column.remoteSort : ($table.sortOpts.remote || remoteSort)
// 如果是服务端排序
if (isRemote) {
this.sortData = {
property: params.property,
field: params.property,
// v3 废弃 prop
prop: params.property,
order: params.order
}
if (proxyConfig) {
this.commitProxy('query')
}
}
UtilTools.emitEvent(this, 'sort-change', [Object.assign({ $grid: this }, params)])
},
filterChangeEvent (params) {
align: _vm.align,
headerAlign: _vm.headerAlign,
footerAlign: _vm.footerAlign,
showOverflow: _vm.showOverflow,
showHeaderOverflow: _vm.showHeaderOverflow,
className: _vm.class || _vm.className,
headerClassName: _vm.headerClassName,
footerClassName: _vm.footerClassName,
indexMethod: _vm.indexMethod,
formatter: formatter,
sortable: _vm.sortable,
sortBy: _vm.sortBy,
sortMethod: _vm.sortMethod,
remoteSort: _vm.remoteSort,
filters: UtilTools.getFilters(_vm.filters),
filterMultiple: XEUtils.isBoolean(_vm.filterMultiple) ? _vm.filterMultiple : true,
filterMethod: _vm.filterMethod,
filterRender: _vm.filterRender,
treeNode: _vm.treeNode,
cellRender: _vm.cellRender,
editRender: _vm.editRender,
// 自定义参数
params: _vm.params,
// 渲染属性
visible,
defaultVisible: visible,
checked: false,
disabled: false,
level: 1,
rowSpan: 1,
colSpan: 1,
order: null,
constructor ($xetable, _vm, { renderHeader, renderCell, renderData } = {}) {
const $xegrid = $xetable.$xegrid
const proxyOpts = $xegrid ? $xegrid.proxyOpts : null
const formatter = _vm.formatter
const visible = XEUtils.isBoolean(_vm.visible) ? _vm.visible : true
if (_vm.cellRender && _vm.editRender) {
UtilTools.warn('vxe.error.cellEditRender')
}
if (_vm.type === 'index') {
UtilTools.warn('vxe.error.delProp', ['index', 'seq'])
} else if (_vm.type === 'selection') {
UtilTools.warn('vxe.error.delProp', ['selection', 'checkbox'])
} else if (_vm.type === 'expand') {
if ($xetable.treeConfig && $xetable.treeOpts.line) {
UtilTools.error('vxe.error.treeLineExpand')
}
if (_vm.slots && !_vm.slots.content && _vm.slots.default) {
UtilTools.warn('vxe.error.expandContent')
}
}
if (formatter) {
XEUtils.arrayEach(listElem.querySelectorAll(`.col--group`), thElem => {
let column = this.getColumnNode(thElem).item
let { showHeaderOverflow } = column
let cellOverflow = XEUtils.isBoolean(showHeaderOverflow) ? showHeaderOverflow : allColumnHeaderOverflow
let showEllipsis = cellOverflow === 'ellipsis'
let showTitle = cellOverflow === 'title'
let showTooltip = cellOverflow === true || cellOverflow === 'tooltip'
let hasEllipsis = showTitle || showTooltip || showEllipsis
let childWidth = 0
let countChild = 0
if (hasEllipsis) {
XEUtils.eachTree(column.children, item => {
if (!item.children || !column.children.length) {
countChild++
}
childWidth += item.renderWidth
})
thElem.style.width = `${childWidth - countChild - (border ? 2 : 0)}px`
}
})
XEUtils.each(customMap, ({ visible, resizeWidth }, field) => {
let column = keyMap[field]
if (column) {
if (XEUtils.isNumber(resizeWidth)) {
column.resizeWidth = resizeWidth
}
if (XEUtils.isBoolean(visible)) {
column.visible = visible
}
}
})
comp.refreshColumn()
},
style: headerCellStyle ? (XEUtils.isFunction(headerCellStyle) ? headerCellStyle(params) : headerCellStyle) : null,
on: thOns,
key: columnKey || isColGroup ? column.id : columnIndex
}, [
h('div', {
class: ['vxe-cell', {
'c--title': showTitle,
'c--tooltip': showTooltip,
'c--ellipsis': showEllipsis
}]
}, column.renderHeader(h, params)),
/**
* 列宽拖动
*/
!fixedHiddenColumn && !isColGroup && (XEUtils.isBoolean(column.resizable) ? column.resizable : resizable) ? h('div', {
class: ['vxe-resizable', {
'is--line': !border
}],
on: {
mousedown: evnt => this.resizeMousedown(evnt, params)
}
}) : null
])
}).concat(scrollbarWidth ? [
h('th', {
errorModuleName = 'Edit'
} else if (!VXETable._valid && this.editRules) {
errorModuleName = 'Validator'
} else if (!VXETable._keyboard && (this.keyboardConfig || this.mouseConfig)) {
errorModuleName = 'Keyboard'
} else if (!VXETable._resize && this.autoResize) {
errorModuleName = 'Resize'
}
if (errorModuleName) {
throw new Error(UtilTools.getLog('vxe.error.reqModule', [errorModuleName]))
}
if (scrollY) {
Object.assign(scrollYStore, {
startIndex: 0,
visibleIndex: 0,
adaptive: XEUtils.isBoolean(scrollY.adaptive) ? scrollY.adaptive : true,
renderSize: XEUtils.toNumber(scrollY.rSize),
offsetSize: XEUtils.toNumber(scrollY.oSize)
})
}
if (scrollX) {
Object.assign(scrollXStore, {
startIndex: 0,
visibleIndex: 0,
renderSize: XEUtils.toNumber(scrollX.rSize),
offsetSize: XEUtils.toNumber(scrollX.oSize)
})
}
this.loadTableData(data).then(() => {
if (data && data.length) {
this.inited = true
this.handleDefaults()