Get Grid Value of a particular field in a row for a related

Posted by IramK on 02-Jan-2015 09:17

Hello,

I have three fields in a related grid control and I would like to get the onchange event of my second field. I can catch the onupdate() event of the grid control but how do I get the onchange event of a specific field in my grid control? Kindly let me know.

Cheers.

Posted by Mohammed Siraj on 12-Nov-2017 23:33

Hi Iram,

We have introduced Revised GridControl component and integrated it with client-side SDK support in NewUI.

As you are aware for form fields on a form page we have a FieldContext abstraction, via which you can add change event handlers against specific fields.

For fields in a GridControl component, there is a specialization of FieldContext, called GridFieldContext with some additional GridControl specific API methods.

Now for the requirement on hand, you can attach an onchange handler specifically to the given GridControl field as follows:

var gridFieldContextA = rbf_getGridFieldContext( 0, //gridNo.

                                                                               10, // gridRow index

                                                                               'total'); // fieldName

gridFieldContextA.addOnChangeHandler( function(){} );

Alternatively, on the GridControl field update event which fires for every field change in a GridControl component, you can specifcally request for the modified field using, GridControlComponent interface method getLastModifiedField(); This will return GridFieldContext object of the last modified field:

var gridControlComp = rbf_getGridControlComponent( 0 );//argument is gridNo.

var gridFieldContextA = gridControlComp.getLastModifiedField();

For more API details please refer:

documentation.progress.com/.../

documentation.progress.com/.../

All Replies

Posted by matman on 02-Jan-2015 09:32

Hi Iram,

One of the ways to catch a specific field's onChange event is by using JQuery. An example of such a script could look like this:

<script>
	$(function() {
		$("#rbi_grid_0_0_password").change(function() {
			alert("Hello!");
		});
	});
</script>

As you can see I set the ID of the specific grid field, which I looked up using my source code explorer. The script above only supports the onChange event of one field. An example of a more dynamic onChange event catching script could look like this:

<script>
	$(function() {
		$("td[id$='_password']").change(function() {
			alert("Hello!");
		});
	});
</script>

Now, using JQuery and the Rollbase Client-side AJAX API and it's Grid control functions, you can extend your script to decide which grid row was affected etc.

This is something I used to get what I wanted, but it's more easy and time saving to use the onUpdate event of the grid.

Posted by IramK on 02-Jan-2015 09:46

Yes onUpdate is good but how do I direct it to changing only a particular field rather than checking all fields onUpdate?

Posted by matman on 02-Jan-2015 09:57

I tested soemthing to see whether something I thought about is possible. You can set onUpdate() to call your function with the grid number, grid row as parameters. But you can also give the name of your field using this.name. Example:

onUpdate="yourFunction(##, @@, this.name);"

Your function will then get something like yourFunction(0, 0, "password_0_0"). Using 

function yourFunction(gridNo, gridRow, fieldName) {
	fieldName.substr(0, fieldName.indexOf('_')); 
}

you can get the name of the field (before _0_0) and compare it to your other fields. Using this you could decide which function to call.

Posted by IramK on 02-Jan-2015 10:07

Also do you have any idea that when an OnUpdate is called on change of a field.. it calls it multiple times rather than one. Any suggestions why?

Posted by matman on 02-Jan-2015 10:33

In my experience it only calls the onUpdate once, what kind of fields do you have? Do you somehow affect the other rows?

Posted by IramK on 02-Jan-2015 10:45

Ok I'll check that again. Thanks for your answers.

Posted by matman on 05-Jan-2015 02:12

You're welcome! Feel free to keep me updated so I can assist you if needed :)

Posted by IramK on 02-Nov-2017 09:57

Hi [mention:8397e63abfcb4743aa450d5d1919f4a0:e9ed411860ed4f2ba0265705b8793d05] ,

This doesn't currently work in the latest version i.e. V4.5.2. [mention:78c86023544844079dc6455a4a7a4d57:e9ed411860ed4f2ba0265705b8793d05] Would you be able to help me out with this issue?

[mention:19ab3cfcb5874e299e3c7514268ac01e:e9ed411860ed4f2ba0265705b8793d05] : Any thoughts?

Cheers.

Iram

Posted by Mohammed Siraj on 12-Nov-2017 23:33

Hi Iram,

We have introduced Revised GridControl component and integrated it with client-side SDK support in NewUI.

As you are aware for form fields on a form page we have a FieldContext abstraction, via which you can add change event handlers against specific fields.

For fields in a GridControl component, there is a specialization of FieldContext, called GridFieldContext with some additional GridControl specific API methods.

Now for the requirement on hand, you can attach an onchange handler specifically to the given GridControl field as follows:

var gridFieldContextA = rbf_getGridFieldContext( 0, //gridNo.

                                                                               10, // gridRow index

                                                                               'total'); // fieldName

gridFieldContextA.addOnChangeHandler( function(){} );

Alternatively, on the GridControl field update event which fires for every field change in a GridControl component, you can specifcally request for the modified field using, GridControlComponent interface method getLastModifiedField(); This will return GridFieldContext object of the last modified field:

var gridControlComp = rbf_getGridControlComponent( 0 );//argument is gridNo.

var gridFieldContextA = gridControlComp.getLastModifiedField();

For more API details please refer:

documentation.progress.com/.../

documentation.progress.com/.../

Posted by IramK on 13-Nov-2017 03:26

Thanks for your answer Siraj. Is this API and onChangeHandler available in V4.5.2?

Posted by Mohammed Siraj on 13-Nov-2017 03:49

Yes, please just ensure that Revised Grid Control is enabled as a tenant level preference.

Posted by IramK on 13-Nov-2017 04:15

Sure, will do.

Thanks.

This thread is closed