replied on March 18, 2018
thank you for your answer. I am very sorry to mention that I modified the code to trigger the add or delete on table change event.
// test
//copy table
$('.Tabletest1 ').on('change',function(){
//Make the tables the same size
var sLen1 = $('.Tabletest1 tbody tr').length;
var dLen1 = $('.tabletest2 tbody tr').length;
if (sLen1 > dLen1){
for(var j=0; j< sLen1-dLen1; j++){
$('.tabletest2 .cf-table-add-row').click();
}
} else if (dLen1 > sLen1){
for(var j=0; j< dLen1-sLen1; j++){
$('.tabletest2 tbody tr:last-child .cf-table-delete').click();
}
}
//Copy the data
$('.Tabletest1 tbody tr').each(function(){
var i = $(this).index();
$(this).find('td').each(function(){
var title = $(this).attr('data-title');
//Check if this is a Radio button or Checkbox item, handle it accordingly
if ($(this).find('span.choice').length >0){
$(this).find('span.choice').each(function(){
var eIndex = $(this).index();
$('.tabletest2 tbody tr:nth-child('+(i+1).toString()+') td[data-title="'+title+'"] div span:nth-child('+(eIndex+1).toString()+') input').prop('checked',$(this).find('input').is(':checked'));
});
} else {
//Otherwise, just copy the one input/select element
$('.tabletest2 tbody tr:nth-child('+(i+1).toString()+') td[data-title="'+title+'"] [id^="Field"]').val($(this).find('[id^="Field"]').val());
}
});
});
});
My code is attached. I can trigger the table 2 add row when i click on add row on table 1 but when i delete the row on table 1 the delete on table 2 did not trigger.