Script: -Comment sélectionner toutes les cases de la table en utilisant javascript
<script type="text/javascript">
$(document).ready(function() {
$("#cbSelectAll").click(function() {
if (this.checked) {
$(':checkbox').each(function() {
this.checked = true;
var selectall = document.getElementsByClassName(".checkBoxClass");
var cid = $(this).attr('id');
console.log('cid' + cid);
var hidSelectAll = document.getElementById("hfSelectAll");
var hidCustomer = document.getElementById("hfCustomerID");
hidCustomer = '';
var str = 'Select All';
hidSelectAll.value = str;
console.log(hidSelectAll);
});
$("#GridRows .checkBoxClass").change(function() {
if (!$(this).prop("checked")) {
$("#cbSelectAll").prop("checked", false);
var cid = $(this).attr('id');
console.log('cid' + cid);
var hidSelectAll = document.getElementById("hfSelectAll");
var str = 'Select All + unselected values';
hidSelectAll.value = str;
console.log(hidSelectAll);
}
});
}
else {
$(':checkbox').each(function() {
this.checked = false;
var hidSelectAll = document.getElementById("hfSelectAll");
var str = 'UnSelect All';
hidSelectAll.value = str;
console.log(hidSelectAll);
});
$(".checkBoxClass").change(function() {
if (!$(this).prop("checked")) {
$("#cbSelectAll").prop("checked", false);
var hidSelectAll = document.getElementById("hfSelectAll");
var str = 'unSelect All + selected values';
hidSelectAll.value = str;
console.log(hidSelectAll);
}
});
}
});
});
</script>
HTML: -
<body>
<h4>Number Of Records - <span>@ViewBag.ItemCount</span> </h4>
<div class="table-responsive" style="padding-left:20%;">
<table class="table-fill" style="float:left;">
<thead>
<tr>
<th class="text-left">
Select All
<div class="checkbox">
<input style="margin-left:15px;" type="checkbox" id="cbSelectAll" />
</div>
</th>
<th class="text-left" style="padding-left:27px;">
First Name
</th>
<th class="text-left" style="padding-left:32px;">
Last Name
</th>
<th class="text-left" style="padding-left:40px;padding-right: 60px;">
Email-ID
</th>
<th class="text-left" style="padding-left:30px;padding-right: 40px;">
Customer Type
</th>
<th class="text-left" style="padding-left:15px;">
Customer Designation
</th>
</tr>
</thead>
</table>
<div id="GridRows" style="width:65%;">
</div>
</div>
<div id="pager"></div>
<input type="hidden" id="currentPage">
<input type="hidden" id="hfCustomerID"/>
<input type="hidden" id="hfSelectAll" />
</body>
c'est html. Lignes générées dynamiquement à partir de l'appel jquery ajax pour éviter la perte de valeurs stockées dans un champ masqué lors du chargement de la page.
En cochant cette case, toutes les valeurs de la table de la même page sont sélectionnées. Comment enregistrer toutes les valeurs d'une table à partir d'une pagination multiple lorsque vous avez cliqué sur dans la case Sélectionner tout?
Quelles sont les options pour stocker toutes les valeurs de la table?
Pouvez-vous s'il vous plaît ajouter le code HTML de la page –