Get Grid Value of a particular field in a row for a related grid control - Forum - Rollbase - Progress Community

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

 Forum

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

This question is answered

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.

Verified Answer
  • 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/.../

    Regards,
    Siraj.
All Replies
  • 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.

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

  • 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.

  • 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?

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

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

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

  • Hi ,

    This doesn't currently work in the latest version i.e. V4.5.2. Would you be able to help me out with this issue?

     : Any thoughts?

    Cheers.

    Iram

  • 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/.../

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

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

    Regards,
    Siraj.
  • Sure, will do.

    Thanks.