Hi there,
kindly help me with this problem. I want checkbox with default functionality of the grid like (add Row ,EditRow,DeleteRow,) in context menu .because.
is not found grid property.
I want both. checkbox and default functionality
kindly help me with this problem.
Hi there,
Thank you for your response kindly help me this issue as soon as possible.
|
App.component.ts
public itemBeforeEvent(args: MenuEventArgs) {
if (args.item.text !== 'Edit') {
let shortCutSpan: HTMLElement = createElement('span');
let text: string = args.item.text;
args.element.textContent = '';
let inputEle = createElement('input');
inputEle.type = 'checkbox';
inputEle.setAttribute('class', 'e-checkbox');
shortCutSpan.innerText = text;
args.element.appendChild(inputEle);
args.element.appendChild(shortCutSpan);
}
}
onSelect(args) {
if (
!args.event.target.classList.contains('e-checkbox') &&
args.item.text !== 'Edit'
) {
var checkbox = args.element.querySelector('.e-checkbox');
checkbox.checked = !checkbox.checked;
}
if (args.item.text === 'Edit') {
if (this.grid.getSelectedRecords().length) {
this.grid.startEdit(); // handle the grid actions as per your requirement here.
} else {
alert('Select any row');
}
}
} |
|
App.component.html
<ejs-contextmenu
id="contextmenu"
#contextmenu
target=".e-content"
[items]="menuItems"
(select)="onSelect($event)"
(beforeItemRender)="itemBeforeEvent($event)"
></ejs-contextmenu
>` |
Hi there ,
Thank you for your response who can i add these option AddRows . AddChild , AddParent in custom context menu in grid. These option only available in default contexts menu is there is any function available for it in custom context menu .
|
App.compoennt.ts
ngOnInit(): void {
this.data = orderDetails;
this.contextMenuItems = [
{
text: 'Enable Selection',
iconCss: 'c-custom', // add this class names to select from the list elements
target: '.e-content',
id: 'selection',
},
{
text: 'Enable DragandDrop',
iconCss: 'c-custom',
target: '.e-content',
id: 'drag',
},
'AutoFit',
'AutoFitAll',
'SortAscending',
'SortDescending',
'Copy',
'Edit',
'Delete',
'Save',
'Cancel',
'PdfExport',
'ExcelExport',
'CsvExport',
'FirstPage',
'PrevPage',
'LastPage',
'NextPage',
];
this.editing = { allowDeleting: true, allowEditing: true };
}
contextMenuOpen(args) {
if (this.isInitialLoad) {
this.isInitialLoad = false;
var parentNode = [];
var customEle = args.element.querySelectorAll('.c-custom');
if (customEle.length) {
customEle.forEach((innerEle) => {
parentNode.push(innerEle.parentElement);
});
console.log(parentNode);
parentNode.forEach((ele) => {
var text = ele.textContent;
ele.innerText = '';
let inputEle = createElement('input');
inputEle.type = 'checkbox';
inputEle.setAttribute('class', 'e-checkbox');
ele.prepend(inputEle);
let spanEle = createElement('span');
spanEle.textContent = text;
spanEle.setAttribute('class', 'e-checkboxspan');
ele.appendChild(spanEle); // append checkbox for custom items
});
}
}
}
contextMenuClick(args) {
if (args.event.target.classList.contains('e-checkboxspan')) {
var checkbox = args.element.querySelector('.e-checkbox');
checkbox.checked = !checkbox.checked; // maintain the checkbox state here
}
}
|