Update an element in a grid by JavaScript

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
dieter
Experienced User
Posts: 122
Joined: Tue May 22, 2012 6:45 am
First Name: Dieter
Last Name: Schröder
Company Name: Ecclesia Holding GmbH
State / Province: Outside Canada/USA
Country: Germany
Contact:

Update an element in a grid by JavaScript

Post by dieter »

Hello,
i have a subfile with a checkbox. When the user clicks on a row i want to set the value of the checkbox in that row by JavaScript. If the user directly clicks the checkbox all works fine. But i want to switch the checkbox value also when the user clicks somewhere in the row. I tried to do that with the onrowclick event of the grid.
The name of the checkbox element is "auswahl". So this is my code:
changeElementValue("auswahl", "J");

I think the problem is that in a grid the real element ID is not auswahl but somethink "auswahl.1", "auswahl.2", depending of the grid row. Is that right?
In the documentation i found a method "getCellValue". Is there a method like "setCellValue" or something like this?

Dieter
emhill
Experienced User
Posts: 116
Joined: Wed Sep 05, 2012 11:14 am
First Name: Eric
Last Name: Hill
Company Name: Integrated Corporate Solutions
Phone: 256-760-8239
Address 1: 501 S Wood Avenue
City: Florence
State / Province: Alabama
Zip / Postal Code: 35630
Country: United States
Contact:

Re: Update an element in a grid by JavaScript

Post by emhill »

Deiter,

We are doing this numerous places. Here is the code for the onrowclick event. SEL is the field name for the checkbox. We are placing an "X" in the field when the box is checked and a blank when not checked:
=============================================
var optId = "SEL." + row;

if (getObj(optId)){

if (!getObj(optId).checked) {
getObj(optId).checked = true;
changeElementValue(optId, "X");
}
else{
getObj(optId).checked = false;
changeElementValue(optId, "");
}
}
=============================================

Hope this helps!!!!
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Update an element in a grid by JavaScript

Post by Scott Klement »

Yes, that is correct, you need to append the record number to the id. So it'd be auswahl.1, auswahl.2, etc.

No, there isn't anything like a setDataValue() API. You need to do it by calculating the id.
dieter
Experienced User
Posts: 122
Joined: Tue May 22, 2012 6:45 am
First Name: Dieter
Last Name: Schröder
Company Name: Ecclesia Holding GmbH
State / Province: Outside Canada/USA
Country: Germany
Contact:

Re: Update an element in a grid by JavaScript

Post by dieter »

Thank you for your posts. I just tried it and it works. But after my try i have recogneized that this is not exactly what i need. I didn't tell you that there also is JavaScript Code in the onclick event of the checkbox. Sorry. I want to execute that code also. Is there a possibility to simulate a click on the checkbox? I think pui.click() only works für buttons. E.G. i tried pui.click("auswahl.1") . But this does not work.

Dieter
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Update an element in a grid by JavaScript

Post by Scott Klement »

I'm not aware of an easy way to "simulate" a click on the checkbox.

I would suggest putting the code that's running in the 'onclick' event of the checkbox into a separate JavaScript function (perhaps in a separate JavaScript file). Then you could call this function both from the onclick of the checkbox and from the code that's setting the value programatically.
dieter
Experienced User
Posts: 122
Joined: Tue May 22, 2012 6:45 am
First Name: Dieter
Last Name: Schröder
Company Name: Ecclesia Holding GmbH
State / Province: Outside Canada/USA
Country: Germany
Contact:

Re: Update an element in a grid by JavaScript

Post by dieter »

Thank you Scott. Good idea.
I will try.

(Again special thanks to Eric. Your code gave me some new ideas ...)

Dieter
emhill
Experienced User
Posts: 116
Joined: Wed Sep 05, 2012 11:14 am
First Name: Eric
Last Name: Hill
Company Name: Integrated Corporate Solutions
Phone: 256-760-8239
Address 1: 501 S Wood Avenue
City: Florence
State / Province: Alabama
Zip / Postal Code: 35630
Country: United States
Contact:

Re: Update an element in a grid by JavaScript

Post by emhill »

Dieter,

Maybe create a hidden button on the grid row that has the onclick event handle what you need when the checkbox is checked. Change your onclick event for your checkbox to pui.click("hiddenbutton") and in the onrowclick event add the pui.click("hiddenbutton") under the condition where the checkbox is checked.

Just a thought....
dieter
Experienced User
Posts: 122
Joined: Tue May 22, 2012 6:45 am
First Name: Dieter
Last Name: Schröder
Company Name: Ecclesia Holding GmbH
State / Province: Outside Canada/USA
Country: Germany
Contact:

Re: Update an element in a grid by JavaScript

Post by dieter »

Hello Eric,
cool idea...
I like such cool ideas :-)

Thank you and best regards from Germany.

Dieter
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest