From 0f4a9088a8e2b9290cd419727760fbd2dd9cee86 Mon Sep 17 00:00:00 2001
From: Erhan355 <erhan.hasdagli@external.opet.com.tr>
Date: Sun, 3 Jan 2021 01:43:37 +0300
Subject: [PATCH] ClearMasterCheckbox fix

---
 .../Admin/Views/Shared/_Table.Definition.cshtml      |  4 ++--
 src/Presentation/Nop.Web/wwwroot/js/admin.table.js   | 12 +++++++-----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/_Table.Definition.cshtml b/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/_Table.Definition.cshtml
index 045970e993c..ca5bd8bfd2e 100644
--- a/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/_Table.Definition.cshtml
+++ b/src/Presentation/Nop.Web/Areas/Admin/Views/Shared/_Table.Definition.cshtml
@@ -196,13 +196,13 @@ ordering: @Model.Ordering.ToString().ToLower(),
                 @if (Model.ServerSide)
                 {
                     <text>
-                    updateTable('#@Model.Name', @isMasterCheckBoxUsed.ToString().ToLower());
+                    updateTable('#@Model.Name');
                     </text>
                 }
                 else
                 {
                     <text>
-                    updateTableSrc('#@Model.Name', @isMasterCheckBoxUsed.ToString().ToLower());
+                    updateTableSrc('#@Model.Name');
                     </text>
                 }
             }
diff --git a/src/Presentation/Nop.Web/wwwroot/js/admin.table.js b/src/Presentation/Nop.Web/wwwroot/js/admin.table.js
index c86be692be4..6baf8ccc00b 100644
--- a/src/Presentation/Nop.Web/wwwroot/js/admin.table.js
+++ b/src/Presentation/Nop.Web/wwwroot/js/admin.table.js
@@ -24,7 +24,7 @@ var selectedIds = [];
 
 function clearMasterCheckbox(tableSelector) {
   var selector = '.mastercheckbox';
-  $(selector, tableSelector).prop('checked', false).change();
+  $(tableSelector).closest('.dataTables_scroll').find(selector).prop('checked', false).change();
   selectedIds = [];
 }
 
@@ -37,21 +37,23 @@ function updateMasterCheckbox(tableSelector) {
   $('.mastercheckbox', $(tableSelector)).prop('checked', numChkBoxes == numChkBoxesChecked && numChkBoxes > 0);
 }
 
-function updateTableSrc(tableSelector, isMasterCheckBoxUsed) {
+function updateTableSrc(tableSelector) {
   var dataSrc = $(tableSelector).DataTable().data();
   $(tableSelector).DataTable().clear().rows.add(dataSrc).draw();
   $(tableSelector).DataTable().columns.adjust();
-  
+  var selector = '.mastercheckbox';
+  var isMasterCheckBoxUsed = $(tableSelector).closest('.dataTables_scroll').find(selector).length > 0;
   if (isMasterCheckBoxUsed) {
     clearMasterCheckbox(tableSelector);
   }
 }
 
 
-function updateTable(tableSelector, isMasterCheckBoxUsed) {
+function updateTable(tableSelector) {
   $(tableSelector).DataTable().ajax.reload();
   $(tableSelector).DataTable().columns.adjust();
-
+  var selector = '.mastercheckbox';
+  var isMasterCheckBoxUsed = $(tableSelector).closest('.dataTables_scroll').find(selector).length > 0;
   if (isMasterCheckBoxUsed) {
     clearMasterCheckbox(tableSelector);
   }