How add menu button to ag-Grid row?

蹲街弑〆低调 提交于 2021-01-07 03:23:14

问题


I'm using ag-Grid Enterprise Vue.

I see in the docs how to enable a "context menu" that is available by right-clicking any individual cell.

I instead would love to have a special column (pinned to the right) that has a button (maybe looking like or ...) that opens a menu upon left-click.

How could I go about enabling this? I have found no examples in the docs.

Ag-grid Cell containing menu button is a similar question but has no answer.


回答1:


From this comment on this ag-grid-enterprise issue, I was able to fork the example, and I think it will work for my situation.

The relevant code is:

var gridOptions = {
    columnDefs: columnDefs,
    enableRangeSelection: true,
    getContextMenuItems: getContextMenuItems,
    allowContextMenuWithControlKey: true,
    onCellClicked: params => {
        console.log(params);
        if(params.column.colDef.field === '...'){
            params.api.contextMenuFactory.showMenu(params.node, params.column, params.value, params.event)
        }
    },
    onCellContextMenu: params => {
        params.api.contextMenuFactory.hideActiveMenu()
    }
};

function getContextMenuItems(params) {
    console.log('getContextMenuItems', params);
    const node = params.node;
    console.log('node.id, node.rowIndex, node.data', node.id, node.rowIndex, node.data);
    var result = [
        {
            name: `Alert 'Row ${node.rowIndex + 1}'`,
            action: function() {
                window.alert(`Row ${node.rowIndex + 1}`);
            },
            cssClasses: ['redFont', 'bold']
        },
        'separator',
        {
            name: 'Checked',
            checked: true,
            action: function() {
                console.log('Checked Selected');
            },
            icon: '<img src="../images/skills/mac.png"/>'
        }, 
        'copy' // built in copy item
    ];

    return result;
}


来源:https://stackoverflow.com/questions/64881767/how-add-menu-button-to-ag-grid-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!