Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#829016
Hi,

When I use onAddRow and onDeleteRow more than once, just the last onAddRow or onDeleteRow will be acted and the others will be deactivated.

Example (Just Code 2 will work):
Code: Select all
$(grid_id).onAddRow(function(aNewRow, oGrid, rowIndex) {
	// Code 1
});
$(grid_id).onAddRow(function(aNewRow, oGrid, rowIndex) {
	// Code 2
});
What should I do????
Is there anyway to know when the row is added or deleted from grid to create custom function like onAddRow or onDeleteRow to handle these actions?

Looking forward to hearing from you...
#829019
Hi,
I am not sure to understand your question well. Usually for the same grid_id you only have to define one onAddRow() and one onDeleteRow(). You can't have multiple onAddRow() / onDeleteRow() defined. Put all your testing or checking codes when onAddRow () is needed to check and put all your required checking in onDeleteRow() to do, that's. Cheers
#829020
kirkwg wrote: Sun Mar 14, 2021 9:25 pm Hi,
I am not sure to understand your question well. Usually for the same grid_id you only have to define one onAddRow() and one onDeleteRow(). You can't have multiple onAddRow() / onDeleteRow() defined. Put all your testing or checking codes when onAddRow () is needed to check and put all your required checking in onDeleteRow() to do, that's. Cheers
Thanks,
I am creating a code as library to be used in JavaScript codes of my teammates. As that is a library, they couldn't put their codes into onAddRow function and they will use another onAddRow function to suit their code. Then my onAddRow will be deactivated.

That's the problem!
#829021
Hi,
In general, same function name with same number of parameters cannot be duplicated. In this case you can add your own onAddRow() but with different number of parameter I guess in general practice. Please try I don't know this working or not (function overloading..) , if not simple use another function name, say onAddRowNew() for your Lib. Hope this helps, cheers.

$(grid_id).onAddRow(function(aNewRow, oGrid, rowIndex, extraPara1) {
// Code 2
});
#829024
I am creating a code as library to be used in JavaScript codes of my teammates. As that is a library, they couldn't put their codes into onAddRow function and they will use another onAddRow function to suit their code. Then my onAddRow will be deactivated.
You may use an Array of functions for this purpose. Tell your teammates to push their onAddRow or onDeleteRow event handler function into a single Array defined globally in javascript of form, then you can loop through the array and run every function in it.

Example code:
Code: Select all
var gOnAddRow = []; // global array for onAddRow event,
gOnAddRow.push(function(aNewRow, oGrid, rowIndex) {
    console.log('Function 1');
});

gOnAddRow.push(function(aNewRow, oGrid, rowIndex) {
    console.log('Function 2');
});

// ...
// your teammates could push as many functions as they want into the array

// Then a single event handler could do the job :
$("#grid_id").onAddRow(function(aNewRow, oGrid, rowIndex) {
    for(var index=0;index < gOnAddRow.length;index++)
        gOnAddRow[index](aNewRow, oGrid, rowIndex);
});
You can do the same for onDeleteRow

OR you can bind your event handler for onAddRow on +New button instead:
Code: Select all
$("#grid_id button.pmdynaform-grid-newitem").click(function(buttonElement) { 
    // write your code here
});
but in this case you don't have onAddRow function parameters then you need to get them yourself as you need!
for the onDeleteRow you can bind a click event with:
Code: Select all
$("#grid_id div.remove-row").click(function(buttonElement) { 
    // write your code here
});
Hope it helps!

Hello. For rental housing, there are software solu[…]

Experience heightened pleasure with Cenforce 100 M[…]

Get an instant solution to move emails to MBOX for[…]

Most Demanding OST to PST Converter

The most demanding OST to PST Converter is TrijaT[…]