我已经从这里下载了源代码。我已经检查了演示,但没有在任何地方实现单选下拉功能。所以我修改了最后一行“完成”的代码。因为我想在单元格编辑上实现下拉功能。以下是现有源代码中用于单选下拉菜单的代码更改。
------grid-formatter.component.ts-----
const customEnableButtonFormatter: Formatter = (row: number, cell: number, value: any, columnDef: Column, dataContext: any, grid: any) => {
if (value == 'Yes') {
return '<select style="font-size:8px; z-inex:1; font-weight:Normal;width:70px;" class="c-select-status c-select-status__text target table-cell-dropdown" id="' + row + '"><option value="Yes" selected>' + 'Yes' + '</option><option value="No">' + 'No' + '</option> "</select>';
}
else {
return '<select style="font-size:8px; z-inex:1; font-weight:Normal;width:70px; " class="c-select-status c-select-status__text target table-cell-dropdown" id="' + row + '"><option value="Yes">' + 'Yes' + '</option><option value="No" selected>' + 'No' + '</option> "</select>';
}
};
this.columnDefinitions = [
{ id: 'title', name: 'Title', field: 'title', sortable: true, type: FieldType.string, width: 70 },
{ id: 'phone', name: 'Phone Number using mask', field: 'phone', sortable: true, type: FieldType.number, minWidth: 100, formatter: Formatters.mask, params: { mask: '(000) 000-0000' } },
{ id: 'duration', name: 'Duration (days)', field: 'duration', formatter: Formatters.decimal, params: { minDecimal: 1, maxDecimal: 2 }, sortable: true, type: FieldType.number, minWidth: 90, exportWithFormatter: true },
{ id: 'complete', name: '% Complete', field: 'percentComplete', formatter: Formatters.percentCompleteBar, type: FieldType.number, sortable: true, minWidth: 100 },
{ id: 'percent2', name: '% Complete', field: 'percentComplete2', formatter: Formatters.progressBar, type: FieldType.number, sortable: true, minWidth: 100 },
{ id: 'start', name: 'Start', field: 'start', formatter: Formatters.dateIso, sortable: true, type: FieldType.date, minWidth: 90, exportWithFormatter: true },
{ id: 'finish', name: 'Finish', field: 'finish', formatter: Formatters.dateIso, sortable: true, type: FieldType.date, minWidth: 90, exportWithFormatter: true },
{ id: 'effort-driven', name: 'Effort Driven', field: 'effortDriven', formatter: myCustomCheckmarkFormatter, type: FieldType.number, sortable: true, minWidth: 100 },
{
id: 'completed', name: 'Completed', field: 'completed', type: FieldType.string, sortable: true, minWidth: 100,
formatter: customEnableButtonFormatter,
onCellClick: (e, args) => {
console.log("*****",args);
}
}
];
this.dataset[i] = {
id: i,
title: 'Task ' + i,
phone: this.generatePhoneNumber(),
duration: (i % 33 === 0) ? null : Math.random() * 100 + '',
percentComplete: randomPercent,
percentComplete2: randomPercent,
percentCompleteNumber: randomPercent,
start: new Date(randomYear, randomMonth, randomDay),
finish: new Date(randomYear, (randomMonth + 1), randomDay),
effortDriven: (i % 5 === 0),
completed:"Yes" <<<<-------important change----I have passed 'Yes' by default
};
------collection_100_numbers.json---
[
{ "value": 0, "label": "Yes" },
{ "value": 1, "label": "No"}
]
现在实际问题是当我在列定义中使用时不会触发 onCellChange() 事件。所以我使用了 onCellClick() 方法。将下拉值更改为 no 或 yes 后,只有每次事件触发为“是”值。为什么会这样?