Ver Mensaje Individual
  #13 (permalink)  
Antiguo 09/06/2012, 22:05
Avatar de diamari
diamari
 
Fecha de Ingreso: marzo-2012
Mensajes: 95
Antigüedad: 12 años
Puntos: 30
Respuesta: Checkbox por grupos en tabla dinámica

Bueno el solución de emprear es uno que creo que puedes implementar aunque tendrías que añadir un poco mas de código php.

Antes que nada quiero preguntar si el código que tienes correr si des-comentas los otros checkall? Pregunto porque a mi no me resulta y de lo visto es debido a que nombraste todo los checkall allbox y pues no conoce cual quieres acceder. Para minimizar los cambios cree un arreglo con ellos y coloque el variable this. También estoy asumiendo que los valores de value son los mostrados. Verifica si esto te funciona:

Código:
<html>
<head>
	<title>Documento sin título</title>
</head>
<script>
function CheckAll(cajaCheck) {
	if (cajaCheck == document.peruid['allbox[]'][0]){
		for (var i=0;i<document.peruid['a_permiso[]'].length;i++){
			document.peruid['a_permiso[]'][i].checked = cajaCheck.checked;}
	}else{
		for (var i=1;i<document.peruid['allbox[]'].length;i++){
			if(cajaCheck == document.peruid['allbox[]'][i]){
				for (var j=0;j<document.peruid['a_permiso[]'].length;j++){
					var largoNum = 0;
					if (i > 9){
						largoNum = 1;
					}
					var miValor = document.peruid['a_permiso[]'][j].value.substr(0,7+largoNum);
					if(miValor == "$modid"+i){
						document.peruid['a_permiso[]'][j].checked = cajaCheck.checked;
					}
				}
			}			
		}
	}
}


function CheckCheckAll() {
	var TotalBoxes = 0;
	var TotalOn = 0;
	for (var i=0;i<document.peruid.elements.length;i++) {
		var e = document.peruid.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox')) {
			TotalBoxes++;
			if (e.checked) {
				TotalOn++;
			}
		}
	}
	if (TotalBoxes==TotalOn) {
		document.peruid.allbox.checked=true;
	} else {
		document.peruid.allbox.checked=false;
	}
}

</script>
<body>
<form method="post" name="peruid">
<table border="1" width="80%" cellpadding="0" cellspacing="0">	
<tr>
<td width="20%">TODOS<br><input name="allbox[]" onClick="CheckAll(this);" type="checkbox" value="._CHECKALL."></td>
<td width="20%" colspan="4" align="center">PERMISOS DE GESTION A USUARIO XXXXX</td>
</tr>

<tr>
<td width="20%">DIVISIONES O PROYECTOS($bd)<br></td>
<td width="20%" align="center">Module($modid1)<br>DOC<br><input name="allbox[]" onclick="CheckAll(this);" type="checkbox" value="._CHECKALL."></td>
<td width="20%" align="center">Module($modid2)<br>GCMA<br><input name="allbox[]" onclick="CheckAll(this);" type="checkbox" value="._CHECKALL." ></td>
<td width="20%" align="center">Module($modid3)<br>PROY<br><input name="allbox[]" onclick="CheckAll(this);" type="checkbox" value="._CHECKALL." ></td>
<td width="20%" align="center">Module($modid4)<br>SCRM<br><input name="allbox[]" onclick="CheckAll(this);" type="checkbox" value="._CHECKALL." ></td>
</tr>
<tr>
<td width="20%">$bd1 PROYECTO1</td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid1$bd1"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid1$bd2"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid1$bd3"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid1$bd4"></td>
</tr>
<tr>
<td width="20%">$bd2 PROYECTO 2</td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid2$bd1"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid2$bd2"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid2$bd3"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid2$bd4"></td>
</tr>
<tr>
<td width="20%">$bd3 DIVISION 3</td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid3$bd1"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid3$bd1"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid3$bd3"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid3$bd4"></td>
</tr>
<tr>
<td width="20%">$bd4 DIVISION 4</td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid4$bd1"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid4$bd2"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid4$bd3"></td>
<td width="20%" align="center"><input type="checkbox" name="a_permiso[]" value="$modid4$bd4"></td>
</tr>
</table>
</form>
</body>
</html>
Un poco mas complicado de lo que me gustaría pero dado los restricciones creo que no esta muy fuera de control.