I see a lot of posts on here regarding clearing all the values within a table, but I just want to clear the table entirely (rows and all) by clicking the X button for all rows.
My thought was to use the following code to do this
$('.cf-table-delete').each(function(){ console.log('Found Delete Button with Index: ' + $(this).closest("tr").index()); $(this).trigger('click'); });
However the array returns some really strange out of bound indexes and very few of the actual delete buttons shown on screen.
Here is the console output from trying to delete a table with 3 rows for example
We found 3 with an index of 0, 1 out of bounds with an index of -1, and 2 with an index of 1. Out of all 6 of these, only 1 was actually on the form, leaving 2 rows not deleted. No matter how many rows I have, it always only finds 1 of the actual delete buttons, leaving behind all other rows.
In this example I am starting with 3 rows, I run the function once and it deletes only 1 row, then I run it again and it deletes another row. If I keep running the function, all the rows will eventually be deleted one at a time.
In further testing I found it works as expected as long as the table has no read-only fields for some reason, but I want to clear all tables of all rows, regardless of what is in them. I simply want to click every row delete button found on the form.