get the value of certain row of the grid from within client?

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

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

get the value of certain row of the grid from within client?

#1

Postby t4nu » Fri May 20, 2016 7:31 am

Hi,
I want to get the value of certain cell of the grid from within the client, is it the same with when I tried to get the cell from within the server side script? If so why I always got blank (null) value? If it is different then is there any example in doing so?
Thanks in advance for the help.
0 x

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

#2

Postby Jon » Fri May 20, 2016 8:33 am

No it's not the same: the server might not be up to date with changes made in the client, plus the server has the notion of "current row" but this is only set when the user clicks on something which results in a server side event. The client has no such "current row" concept.

You can get the value of a table column in the client when something else on the same row is clicked with something like this:

Code: Select all

var x= $(this).closest("tr").find(".xxxx").text(); 
..where xxxx is the class assigned to the column in HTML Element Properties. This uses jQuery to find the parent row then searches for the column using its class name. Use the text() method if the column is display only, use val() if it's an input field.

If you want to get a table column from any other context (other than from a click on the same row), it's a bit harder. You need to assign a unique class name to each cell on the server, e.g. using the columnDataClass property, and then search for this on the client. I don't have an example of doing this I'm afraid.
Last edited by Jon on Mon May 23, 2016 9:56 am, edited 1 time in total.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#3

Postby t4nu » Mon May 23, 2016 7:04 am

Hi Jon,
I have tried this:
1. Put the class name (AdvanceNo) on the 1st column in
the tab Editor Input
2. Put the class name on the 2nd column in the tab Editor Input
3. Put the code in the event handlers of the 2nd column in the jQuery tab.
The code put in the click event and is looking like this:

Code: Select all

    var x = $(this).parent("tr").find(".AdvanceNo").text();

    alert(x);

    return false;
    
but it always give blank result.

What should I check to resolve that problem?
Thanks in advance for the help.
Jon wrote:No it's not the same: the server might not be up to date with changes made in the client, plus the server has the notion of "current row" but this is only set when the user clicks on something which results in a server side event. The client has no such "current row" concept.

You can get the value of a table column in the client when something else on the same row is clicked with something like this:

Code: Select all

var x= $(this).parent("tr").find(".xxxx").text(); 
..where xxxx is the class assigned to the column in HTML Element Properties. This uses jQuery to find the parent row then searches for the column using its class name. Use the text() method if the column is display only, use val() if it's an input field.

If you want to get a table column from any other context (other than from a click on the same row), it's a bit harder. You need to assign a unique class name to each cell on the server, e.g. using the columnDataClass property, and then search for this on the client. I don't have an example of doing this I'm afraid.
0 x

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

#4

Postby Jon » Mon May 23, 2016 7:56 am

Try closest() instead of parent() - I think parent() only searches up one level in the HTML structure whereas closest() carries on searching. If this doesn't work, I suggest looking closely at the generated HTML to check its structure. Then put a breakpoint on the line of JS code and use a debugger to evaluate each part of the statement in turn till you find the one that fails i.e.

$(this)
then..
$(this).parent("tr")
then..
$(this).parent("tr").find(".AdvanceNo")

I use firebug to do this, but any debugger should be capable.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#5

Postby t4nu » Mon May 23, 2016 8:50 am

Thanks a lot, Jon. It solved my problem.
Jon wrote:Try closest() instead of parent() - I think parent() only searches up one level in the HTML structure whereas closest() carries on searching. If this doesn't work, I suggest looking closely at the generated HTML to check its structure. Then put a breakpoint on the line of JS code and use a debugger to evaluate each part of the statement in turn till you find the one that fails i.e.

$(this)
then..
$(this).parent("tr")
then..
$(this).parent("tr").find(".AdvanceNo")

I use firebug to do this, but any debugger should be capable.
0 x

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

#6

Postby Jon » Mon May 23, 2016 9:57 am

parent() changed to closest() in the original response.
0 x

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

#7

Postby Segi » Mon May 23, 2016 4:11 pm

Just a tip since I do this a lot.

If you add a click event in HTML entities with a single line of code (I usually add a single alert message like alert("test")) you can load up your page in a browser and press F12 to open the developer console.

In Google Chrome you go to Sources. In Firefox, you go to Debugger. The script that you have to debug is called jQueryEventRegistration. Find the alert line and add a breakpoint by clicking on the line number.

When the click event is triggered, it'll stop at the alert message which gives you the opportunity to use the console to get the value. I like doing it this way because you can enter this command in real time and get an immediate result until you find the right string to traverse the DOM to get the value that you need from the table.
0 x

t4nu
Ebase User
Posts: 305
Joined: Thu Jul 02, 2015 8:32 am
Location: Indonesia

#8

Postby t4nu » Tue May 24, 2016 3:43 am

Thank you very much for the tip.
Segi wrote:Just a tip since I do this a lot.

If you add a click event in HTML entities with a single line of code (I usually add a single alert message like alert("test")) you can load up your page in a browser and press F12 to open the developer console.

In Google Chrome you go to Sources. In Firefox, you go to Debugger. The script that you have to debug is called jQueryEventRegistration. Find the alert line and add a breakpoint by clicking on the line number.

When the click event is triggered, it'll stop at the alert message which gives you the opportunity to use the console to get the value. I like doing it this way because you can enter this command in real time and get an immediate result until you find the right string to traverse the DOM to get the value that you need from the table.
0 x


Who is online

Users browsing this forum: No registered users and 25 guests