Skip to content
Merged
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
28 changes: 18 additions & 10 deletions packages/vue/src/grid/src/adapter/src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,32 @@ function getEvents(renderOpts, params, context) {
}

function renderOptions(h, options, renderOpts, params, context) {
let { optionProps = {} } = renderOpts
let labelProp = optionProps.label || 'label'
let valueProp = optionProps.value || 'value'
let { column, row } = params
let { formatConfig } = column.own
let cellValue = isSyncCell(renderOpts, params, context) ? getCellValue(row, column) : column.model.value
const { optionProps = {} } = renderOpts
const labelProp = optionProps.label || 'label'
const valueProp = optionProps.value || 'value'
const { column, row } = params
const { formatConfig } = column.own
const cellValue = isSyncCell(renderOpts, params, context) ? getCellValue(row, column) : column.model.value

if (!options && formatConfig && formatConfig.data) {
options = formatConfig.data
}

return options.map((item, index) => {
let attrs = {
domProps: { value: item[valueProp], selected: item.value === cellValue },
let hasSelected = false
const optionsList = options.map((item, index) => {
const selected = item.value === cellValue
if (selected) {
hasSelected = true
}
const attrs = {
domProps: { value: item[valueProp], selected },
key: index
}
return h('option', attrs, item[labelProp])
})
if (options.length && !hasSelected) {
optionsList.unshift(h('option', { style: 'display:none', selected: true }, ''))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A hidden default option is added to ensure that the first option can be selected when the value is empty. This change prevents the issue where no option is selected by default.

}
return optionsList
}

function renderOptgroups(h, options, params, context) {
Expand Down
Loading