I have downloaded source code from here. I have checked demo but single select dropdown functionality not implemented anywhere. so i have modified code for last row "completed". Because i want to implement dropdown functionality on cell edit. following are code changes in existing source code for single select dropdown.
------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"}
]
Below is look and feel of my dropdown in cell
Now actual Question is onCellChange() event not trigger when i used in columndefination. So i have used onCellClick() method. After changing dropdown value as no or yes then only every time event firing as "Yes" value only. Why its so?