2

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"
}, 
Sow Hari
  • 35
  • 7

1 Answers1

5

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.

handlebears
  • 2,168
  • 8
  • 18
  • Thank you, I will try now. But the problem for me is am in entirely different route , Means we maintain User Management route separately and profile/:id separately. But let me give it a short – Sow Hari May 09 '18 at 11:57
  • I made the path relative like making the profile route under usermanagement but no luck. Always my a tag shows an href ="#" with the same error – Sow Hari May 09 '18 at 12:11
  • @SowHari I think you misunderstood handlebears' answer. You passed the expected url path to `routeName`, but an ember routename is effectively the file path to the route you want to render, e.g. if the target route's js file is in `...\myproject\app\routes\profile\user.js`, then it would be `profile.user` (i.e. the part between `...\routes\ ` and the final `.js` with periods as separators. The (url) path specified in the router.js is irrelevant. – arne.b May 09 '18 at 12:26
  • Confirmed, the `_id` shouldn't be in the routeName, it should be formed out of the words immediately inside `this.route(...)` in the router. So maybe it's just `profile`? I only included `user` for the sake of example – handlebears May 11 '18 at 02:02
  • @handlebears Hi, i tried only profile too earlier itself. May be am doing a mistake, can you share your example you tried? Thanks a lot – Sow Hari May 11 '18 at 11:47
  • Hi , i updated my ember version to 3.1.2 and the error disappeared now. But i am getting a warning " WARNING: This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid." So i think am using routeName wrongly ? – Sow Hari May 12 '18 at 03:53
  • @SowHari here is an example. On this branch I'm linking to, go to http://localhost:4200/users to see it in action. https://github.com/jenweber/super-rentals/tree/stack-overflow-examples – handlebears May 12 '18 at 20:46
  • thank you so much @handlebears . Saw your code and thats how i already call, the only difference being I have the routes at same level, like not users/ user , for me both are at same level like UserM is a route and profile is one more route which takes id and it is in the same level. Also further digging my problem is that the second parameter of the {{link to }} goes as undefined. because id is passed by default , i really dont know how to change the undefined to a valued id. My id comes form mongoose. – Sow Hari May 13 '18 at 15:12
  • github link https://github.com/OneCommunityGlobal/HGNApp.git. You can see in UserManagement Page.(usermanagement.js ) under controllers. if you want to run it login as admin@hgn.net and pwd Test123. http://localhost:4200/#/usermanagement – Sow Hari May 13 '18 at 15:30
  • What is the actual link that you want to be generated? – handlebears May 14 '18 at 04:08
  • I just pushed an example of a non-nested route called "something", same branch as before. I think maybe your profiles data doesn't have an attribute called "id" and maybe it is named something else. – handlebears May 14 '18 at 04:19
  • link generated should be localhost:4200/#/profile/profileid , and ya it is _id . i just saw ur examples yesterday, when we hover over it just shows the link we want to route , but when i hover over it just shows localhost:4200/# – Sow Hari May 14 '18 at 15:32
  • and i checked that in your code the model value is being passed as the id value , but in mine it is passed as undefined , may be it is not taking the _id as id . let me go and try to correct it. – Sow Hari May 14 '18 at 15:39
  • Thanks a lot , i changed my _id to id and it worked . I also tried giving routeProperty to "_id" but it was not taking it . Your example helped me to nail it down . Thanks a lot once again – Sow Hari May 15 '18 at 00:51