cbroeren / ember-context-menu

An ember addon for custom context-menu
https://cbroeren.github.com/ember-context-menu
MIT License
23 stars 15 forks source link

Getting Context Menu to work inside Ember Light Table #30

Closed nelnico closed 6 years ago

nelnico commented 7 years ago

I'm trying to make the context menu work inside an Ember Light Table.
So far, upon right click, I make sure that the row you clicked on is the selected row and bring up a context menu. But inside actions (of contextItems) I seem unable to do anything to determine the selected row and call another method (must be inside the component, cannot outside like you got in the dummy)

Ember n00b, please bear with me....


    contextItems: [
        {
            label: 'Publish Period',
            action(selection, details, event) { 
                  console.log(this);  // = undefined
                  // selectio = []
                  // details = undefined
                  // event = jquery object
            }
        }
    ],
nelnico commented 7 years ago

Wrapping context items in a computed did the trick

contextItems: Ember.computed(function () {
        const ctx = this;
        return [
            {
                label: 'Update',
                action(selection, details, event) {
                    ctx.ctx_update();
                }
            }, {
                label: 'Delete',
                action(selection, details, event) {
                    ctx.ctx_delete();
                }
            }, {
                label: 'Reset Grid',
                action(selection, details, event) {
                    ctx.ctx_resetGrid();
                }
            }
        ];
    }),
cbroeren commented 6 years ago

Closed, because topic starter has a working solution already. Using computed properties will do the trick indeed.