3

I have hooked up the content of ember-table with an ember-data model. I'm trying to get model object underlying the row that is currently selected. I've tried using this.get('selection') but to no avail. My ultimate goal is that i have an associated edit details view in a separate view that sits next to the table (aka list view) with a router (v2) that handles the transitioning between creating new models to insert into the table and edit the currently selected model (or eventually batch edit multiple models in the table). Here's the code sample:

App.TableView = Ember.Table.TablesContainer
    .extend(Ember.Table.RowSelectionMixin).extend({
        selectionBinding: 'controller.selection'
    });

App.TableController = Ember.Table.TableController.extend({
       ...
       selection: null,
       selectionChanged: Ember.observer(function() {
              this.transitionToRoute('selectedModel.edit', this.get('selection'));
       }).observes('selection'),
       ...
peta15
  • 103
  • 7

1 Answers1

1

I have solved this issue. What i hadn't realized is that selection is an enumerable (i'm guessing in preparation for multiple selection which would be awesome!) In the controller:

    selection: null,
    selectionChanged: Ember.observer(function() {
        if(this.get('selection').length) {
            selection0 = this.get('selection')[0];
            this.transitionToRoute('selectedModel.edit', selection0);
        }
    }).observes('selection'),
peta15
  • 103
  • 7
  • Cmd+click (or otherwise ctrl+click) gives you multiple selection. Shift+click works too, but doesn't cover complex cases well IMO. – dechov Mar 19 '13 at 15:55