Christopher
Christopher

Reputation: 11

How to display ng2 -smart table row data in other page after click on the specific row

I want to display the smart table row data on another page. So whenever the user clicks on the row data its routes to the new page with this particular row data.

Please help on this, I am stuck

ThanksThis is mytable in advanced

Upvotes: 1

Views: 1040

Answers (1)

OctavianM
OctavianM

Reputation: 4617

Looking at the ng2-smart-table documentation, it seems like there is a userRowSelect event that this table triggers when the user clicks a row. You can handle that and use the Router to redirect to another page.

You can pass the row data using the extras, something like this:

this.router.navigateByUrl('<path>', { state: data });

and you can access the passed data inside your component that handles the route by using the router again

const state = this.router.getCurrentNavigation()?.extras.state;

but please be aware that the router.getCurrentNavigation method only returns something if called in the constructor (or to be more precise: before the navigation has ended). If you need access to the state outside of the constructor, you can use history.state instead (but this adds another property to whatever data you pass, which is the navigationId).

Upvotes: 1

Related Questions