I have a table in a Partial View that is updated when a user selects an option from two different drop downs which are all a part of one form that is submitted and updates the url. Each row in the table contains a check box, and the header contains a "check all" check box so that you can perform bulk delete actions on the rows in the table. Code for my check all check box is written using JQuery on the Index page for the table (Not the partial html file) and is found below:
$('#check-all').on("click", function () {
var checkAllStatus = this.checked;
$('.task-checkbox').each(function () {
this.checked = checkAllStatus;
});
});
$('.task-checkbox').on("click", function () {
if (this.checked == false) {
$('#check-all')[0].checked = false;
}
if ($('.task-checkbox:checked').length == $('.task-checkbox').length) {
$('#check-all')[0].checked = true;
}
});
On first load of the page, the check all box works exactly as intended. However, if you select an option from one of the drop downs, the partial view is updated and the JQuery above no longer works.
After placing break points and going through lots of different sites and searches, it appears that JQuery is still bound to the old check boxes on the table, and not the new check boxes on the updated partial. Therefore, the check all box no longer works. If you reload the page completely, then the check all box works perfectly. However, I do not want to reload the page when the partial is updated. Hence the use of the partial.
Any ideas? I've tried updating the JQuery on submit of the form that updates the partial, but that triggers before the table is updated and so it still doesn't work. Thanks for any help!