Open Local Page on Table Row Select

I have a Table linked to a Database and I’m trying to open a Dynamic page by selecting a Row from the table(table1) using the onRowSelect event.

Can someone please point out where I’m going wrong?

Thanks

Code Below

export function table1_rowSelect(event) {
//Add your code for this event here:
$w(“#table1”).onRowSelect().link = “/MembersCollection/{ID}”;
$w(“#table1”).onRowSelect().target = “_self”;
}

Hey
If you add console.log(“row clicked!”); to your function I think you will see that the console log never gets printed out to the console. I think you have selected Selection by Cells not Rows in the setup of the table?

You should select Rows to trigger that event.

Andreas thanks for your reply.

I have done as you suggested and the table setting was clicking on Select Rows.

“Row Selected” comes up in the console so it is being selected.

The problem appears to be the definition of the link.

The opening page is a members only page and defined by the ID

the url I think should be MembersCollection/{ID}

but it doesn’t appear to recognise {ID} which should be the members ID that is logged in.

thanks for your help

I seem to onto something now I’ve changed the code to

wixLocation.to(/MembersCollection/${wixUsers.currentUser.id});

however this is trying to select the user ID and not the ID for the row selected in the table.

In the database the ID field defines the selected row and Owner is the User Id - confusing I know.

So Row ID I need to put in place of wixUsers.currentUser.id - any ideas?

ok so you want the selected rows id value. try this

$w(“#myTable”).onRowSelect( (event) => {
let rowData = event.rowData;
} );

rowData will contain a json object with all row data. To get the id you get it through rowData._id

so it will be that id you want.

Hi Andreas,

Thanks again for the help.

I have the code as follows but I must have something wrong with the syntax
as it shows shows the error

Not Found (404) - The requested resource could not be found
no data matched this query: {“$and”:[{“_id”:{“$matches”{“ignoreCase”:true,“spec”[{“type”:“literal”,“value”:“undefined”}]}}}]}, with the pattern: /{_id}

==== Code =====
export function table1_rowSelect(event) {

let rowData = event.rowData;

wixLocation.to(/MembersCollection/${rowData._id});
}

wixLocation.to (“/MembersCollection/” + rowData._id"`);

Heya,
I’m Trying the same, but I always get back the following erro msg:
Wix code SDK error: The url parameter that is passed to the to method cannot be set to the value . It must be of type string.
Any idea?
Thyou!

Any other solution? I need help with this problem. :frowning:

Hi.

import wixLocation from ‘wix-location’;

$w.onReady(function () {
$w(“#yourTableName”).onRowSelect((event) => {
let rowData = event.rowData;
wixLocation.to(/yourPageName/${rowData._id});
});

});

Replace yourTableName with the ID of your table element and yourPageName with the path to your page. The rowData._id should correspond to the field in your dataset that uniquely identifies each row.
you can access the id parameter on the page using wixLocation.query.id.