Question

In the past I've used a vanilla handlebars template to create a table with links to other templates like so.

<tbody>
        {{#each}}
            <tr>
                <th>
                    {{#link-to 'entities.entity' actorId}}{{/link-to}}
                </th>
                {{#each alsoKnownAs}}
                <td>
                    {{this}}
                </td>
                {{/each}}
            </tr>
        {{/each}}
        </tbody>

Using the Ember-Table framework i've refactored that template to

<div style="height: 800px;width: 100%;">
{{table-component
  hasFooter=false
  enableContentSelection=true
  columns=columns
  content=controller}}
</div>

My Controller now looks like

entitiesController = Ember.ArrayController.extend

  sortAscending: true
  sortProperties: ['displayName']
  profile_link: 'entities/profile_link'

  columns: Ember.computed ->

    AKA = Ember.Table.ColumnDefinition.create
      columnWidth: 750
      headerCellName: 'Also Known As'
      textAlign: 'text-align-left'
      getCellContent: (row) -> row['alsoKnownAs'].join(', ')

    displayName = Ember.Table.ColumnDefinition.create
      columnWidth: 200
      headerCellName: 'Entity Name'
      textAlign: 'text-align-left'
      TableCellViewClass: 'profile_link'
      getCellContent: (row) -> row['displayName']

    [displayName, AKA]

and my custom template entities/profile_link

<th>{{#link-to 'entities.entity' actorId}}{{/link-to}}</th>

How do I setup my controller so that when I click on a cell in the 'Entity Name' column it links to my custom template?

Was it helpful?

Solution

Instead of TableCellViewClass: 'profile_link'

you can define the template inline:

tableCellViewClass: Ember.Table.TableCell.extend
        template: Em.Handlebars.compile """
          {{#link-to 'entities.entity' view.cellContent}}
            {{view.cellContent}}
          {{/link-to}}
"""
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top