Client API & Tables

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

geadon
Ebase User
Posts: 68
Joined: Wed Aug 15, 2012 1:22 pm

Client API & Tables

#1

Postby geadon » Wed Sep 25, 2013 8:12 am

Hi,

I have just ventured into the world of the client API. I have a table with a hyperlink column which when clicked will launch a dialog window. I need to be able to pass a parameter to the dialog from the ID column of the row in which the hyperlink was clicked. For example - If I click the link on row 4 of the table, I need to pass the value of the ID column of row 4 to the dialog window.

My question is - how do I retrieve the ID from the current row using client API?

I have the code below which iterates through all the rows, I need to locate a single row.
var table = $eb.getTable("TABLE1");
var iter = table.getRows();

while(iter.next())
{
alert(table.getColumn("ID_COLUMN"));
}
Thank you in advance for any help / advice.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Wed Sep 25, 2013 8:40 am

This type of requirement comes up quite often. I normally do it as shown below which uses jQuery/Javascript on the client - you can't use the client API for this as the server doesn't yet know the user has clicked on a row:

Firstly, assign an HTML class to your ID column using HTML Element Properties. You should probably assign this class to the Editor Input section of the control, but this varies depending on the column type. Lets say this class is "idClass".

Then on the hyperlink click event, you find the id of the current row using jQuery - something like this:

Code: Select all

var id = $(this).parent().parent("td").parent("tr").find(".idClass").text();
alert("id is: " + id);
The exact syntax of this jQuery call varies and you may need to experiment to get it exactly right. But essentially what it's doing is navigating upwards from the clicked hyperlink to the table row (tr tag), then navigating down from there to find the id. If this doesn't work first time - normal in my experience - look at the generated source and check the code matches this. Also, the text() method at the end is applicable for display only columns - it would be val() if this was editable.
0 x

geadon
Ebase User
Posts: 68
Joined: Wed Aug 15, 2012 1:22 pm

#3

Postby geadon » Wed Sep 25, 2013 9:03 am

Thank you Jon. That was an approach I had not considered. Your code worked first time, that doesn't happen very often for me! Just to note that my ID coulmn was display only and I had to use .text() and not .val() to retrieve the value.

Thanks again.
0 x


Who is online

Users browsing this forum: No registered users and 4 guests