Entonces, logré crear una matriz de filas marcadas y las vinculé a un botón. Cuando se hace clic en el botón, todas las filas seleccionadas se abrirán en nuevas pestañas.
Ahora mi problema es que no logré seleccionar todo. Probé varias formas de colocar las filas seleccionadas en una matriz y la que funciona es este código, así que lo seguiré usando:
toggleTick_Change() var chktArr =[]; function toggleTick_Change(){ chktArr = $('.single-row-checkbox:checkbox:checked').map(function(){ return $(this).val(); }).get(); console.log('the checked values are: ' + chktArr); $('#conditional-part').show(); }Pero aún no logró seleccionar todo cuando se selecciona otra casilla de verificación.
A continuación se muestran los botones que abren nuevas pestañas:
function btnPrintCNT_Click(){ console.log('This is from button , the checked values are: ' + chktArr); for(let i = 0 ; chktArr.length > i ; i++){ window.open('?mod=admin&action=consignment&id=' + chktArr[i]); } }Código para la casilla de verificación HTML
<input type="checkbox" id="chkAll" value="{$rows.id}" name="chktArr" style="width: 15px; height: 15px;" class="all-row-checkbox" onchange="toggleTick_Change()" /> <input type="checkbox" id="chkT{$rows.id}" value="{$rows.id}" name="chktArr" style="width: 15px; height: 15px;" class="single-row-checkbox" onchange="toggleTick_Change()" />Código para el botón HTML:
<div class="input-group " role="group" aria-label="..." style="width: 85px; margin-top: 2px; " > <span class="input-group-btn"> <button id="btnPrintCNT" type="button" class="btn btn-sm btn-primary" style="margin: 2px; width: 100px; margin-left: 20px; float: left;" onclick="javascript:btnPrintCNT_Click()">CNT</button> </span> </div>Cualquier sugerencia es muy apreciada.
ok, lo resolví. agrego la declaración if else correctamente. Tampoco uso la función toggleTick_Change onevent y uso class en su lugar. Agrego la clase js-checkbox en mi código html de checkbos.
a continuación se muestra lo principal que cambio en mi función de casillas de verificación
var chktArr =[]; $(document).ready(function() { $('.js-checkbox').change(function() { chktArr = $('.single-row-checkbox:checkbox:checked').map(function(){ return $(this).val(); }).get(); console.log('the checked values are: ' + chktArr); $('#conditional-part').show(); if ($(this).attr('id') === 'chkAll'){ if ($(this).prop('checked') === true){ $('.single-row-checkbox').prop("checked", true); chktArr = $('.single-row-checkbox:checkbox:checked').map(function(){ return $(this).val(); }).get(); console.log('the checked values are: ' + chktArr); $('#conditional-part').show(); }else { $('.single-row-checkbox').prop("checked", false); chktArr = $('.single-row-checkbox:checkbox:checked').map(function(){ return $(this).val(); }).get(); console.log('the checked values are: ' + chktArr); } }else{ } }); });Gracias por todas las sugerencias.