Search code examples
ember.jsember-addon

Ember-models-table addon throws ember warn error while trying to use 'routeName' property


Am using ember-models-table to display table in my applicaiton. The table is great for sorting , pagination etc, but am trying to route from specific row to different page based on the id. it has mentioned in its example to use 'routeName' But when I use it throws the following error:

"Assertion Failed: When calling warn you must provide an options hash as the third parameter. options should include an id property."

My .js coding :

columns:[   
        {
          "propertyName": "firstName",
          "title":"First Name",
          "routeName":"/#/profile/_id"
},

and so on

Thanks for your help.

update: the error is gone after updating ember to ember 3.1.2 but there is a warning and its not functioning properly as expected , where am i going wrong?

my code :

columns:[   
        {
          "propertyName": "firstName",
          "title":"First Name",
          "routeName":"profile"
}, 

Solution

  • If you look at the example app for this addon, you'll see the following syntax for the route:

    {
        propertyName: 'id',
        routeName: 'users.user'
    },
    

    This roughly corresponds to a route like users/1. So, if this is your router:

    Router.map(function() {
      this.route('users', function() {
        this.route('user', { path: '/users/:user_id' });
      });
    });
    

    And here are the columns:

    columns: [
            {
                "propertyName": "something",
                "routeName": "users.user"
            },
            {
                "propertyName": "id",
                "routeName": "users.user"
            }
        ]
    

    Here's the template:

    {{models-table 
    data=model 
    columns=columns
    ...
    }}
    

    routeName should not include the id segment.

    Hover over the anchor tag created to see where it leads to, and make adjustments until it matches where it should go. It will only render when there's a valid route for the link. The path seems like it might be relative, so if you're already on the users route, you may only need to specify user for the routeName.

    I figured this out by searching the addon codebase for routeName and then trying it out with the same kind of format that {{link-to}} helper uses in Ember.

    P.S. this is some missing info in the documentation, so if this addon is helping you out, consider making a PR to help others.