11499 sujets

JavaScript, DOM et API Web HTML5

Bonsoir à tous,

Suite à des problèmes de lenteur (connue) du dataTables
lors de l'emploi de "bVisible":false,
j'ai dû me résigner à repenser à mes codes...

Je n'y arrive pas.
A nouveau dataTables fait des caprices !
Enfin, j'ai sûrement mal programmé...
Mais je n'arrive pas à mettre le doigt sur mon erreur.

Pouvez-vous tenter de m'aider ?
D'avance, je vous remercie pour votre aide !

Voici la page en question !

Voici mes soucis :
1. Lorsque dans le slider-control "taille" (1er slider de la 2e ligne), je bouge le curseur de droite sur "Excellent", le javascript plante dans "newRecherche()".
2. Lorsque je clique dans la partie de droite sur un ou plusieurs critères avancés, le javascript plante dans "newRecherche()"


Pouvez-vous m'aider à boucler ce dataTables ?
Je n'en peux plus !!!

Pour vous aider à y voir plus clair,
J'y ai mis des alert...

Aussi, je vous joins aussi "chargementdata00.php"

 
 <?php
	session_start();
 
	$nbcomparer = 0;
	if (isset($_SESSION['recherche'])) {
		if ($_SESSION['recherche']['stringcomparer'] != "") {
			unset($refcomparer);
			$refcomparer = explode(":", $_SESSION['recherche']['stringcomparer']);
			$nbcomparer = count($refcomparer);
		}
	}
 
	$swCriteres = array();
	if ( isset( $_GET['crit'] )) {
		$criteres = $_GET['crit'];
	} else {
		$criteres = "000000000";
	}
 
	for ($i = 0; $i < 9; $i++) {
		$swCriteres[11+$i] = substr($criteres,$i, 1);
	}
 
	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	 * libell&eacute;s types
	 */
	$indColumn = 5;
	$libelle = array();
	$libelle[1] = array ("", "Rond", "Princesse", "Emeraude", "Radiant", "Ovale", "Poire", "Marquise", "Coeur", "Asscher CS");
	$libelle[4] = array ("D", "E", "F", "G", "H", "I", "J", "K");
	$libelle[3] = array ("Faible", "Bon", "Très bon", "Excellent", "Idéal");
	$libelle[5] = array ("IF", "VVS1", "VVS2", "VS1", "VS2", "SI1", "SI2", "SI3", "I1");
	if ($swCriteres[11] == "1") {
		$indColumn++;
		$libelle[$indColumn] = array ("Faible", "Bon", "Très bon", "Excellent", "Idéal");
	}
	if ($swCriteres[12] == "1") {
		$indColumn++;
		$libelle[$indColumn] = array ("Faible", "Bon", "Très bon", "Excellent", "Idéal");
	}
	if ($swCriteres[15] == "1") {
		$indColumn++;
		$libelle[$indColumn] = array ("Sans", "Très légère", "Légère", "Faible", "Moyenne", "Forte", "Très forte");
	}
	if ($swCriteres[17] == "1") {
		$indColumn++;
		$libelle[$indColumn] = array ("Pointue", "Très petite", "Petite", "Moyenne", "Large");
	}
	$indColumn++;
	$libelle[$indColumn]  = array ("", "GIA", "HRD", "IGI", "EGL", "AGS");
 
	/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	 * Easy set variables
	 */
 
	/* Array of database columns which should be read and sent back to DataTables. Use a space where
	 * you want to insert a non-database field (for example a counter or static image)
	 */
	$aColumns = array();
	$aColumns [] = 'item_id';										/* 00					*/
	$aColumns [] = 'cut';											/* 01					*/
	$aColumns [] = 'carat';											/* 02					*/
	$aColumns [] = 'cut_grade';										/* 03					*/
	$aColumns [] = 'color';											/* 04					*/
	$aColumns [] = 'clarity';										/* 05					*/
	if ($swCriteres[11] == "1") {
		$aColumns [] = 'polish';				/* 06	option11		*/
	}
	if ($swCriteres[12] == "1") {
		$aColumns [] = 'symmetry';				/* 07	option12		*/
	}
	if ($swCriteres[13] == "1") {
		$aColumns [] = 'depth';					/* 08	option13		*/
	}
	if ($swCriteres[14] == "1") {
		$aColumns [] = 'table'; 				/* 09	option14		*/
	}
	if ($swCriteres[15] == "1") {
		$aColumns [] = 'fluo_intensity';		/* 10	option15		*/
	}
	if ($swCriteres[16] == "1") {
		$aColumns [] = 'price_per_carat_ht';	/* 11	option16		*/
	}
	if ($swCriteres[17] == "1") {
		$aColumns [] = 'culet_size';			/* 12	option17		*/
	}
	if ($swCriteres[18] == "1") {
		$aColumns [] = 'length_width';			/* 13	option18		*/
	}
	$aColumns [] = 'delay';											/* 14					*/
	$aColumns [] = 'certificat';									/* 15					*/
	$aColumns [] = 'total_price_ht';								/* 16					*/
	$aColumns [] = 'item_id';										/* 17					*/
 
	/* Indexed column (used for fast and accurate table cardinality) */
	$sIndexColumn = "item_id";
 
	/* DB table to use */
	$sTable = "diamant_data";
 
	/* Database connection information */
	$gaSql['user']       = "***";
	$gaSql['password']   = "***";
	$gaSql['db']         = "***";
	$gaSql['server']     = "***";
 
 
	/* 
	 * MySQL connection
	 */
	$gaSql['link'] =  mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password']  ) or
		die( 'Could not open connection to server' );
 
	mysql_select_db( $gaSql['db'], $gaSql['link'] ) or 
		die( 'Could not select database '. $gaSql['db'] );
 
	mysql_set_charset( 'utf8' ); 	
 
 
	/* 
	 * Paging
	 */
	$sLimit = "";
	if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
	{
		$sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
			intval( $_GET['iDisplayLength'] );
	}
 
 
	/*
	 * Ordering
	 */
	$sOrder = "";
	if ( isset( $_GET['iSortCol_0'] ) )
	{
		$sOrder = "ORDER BY  ";
		for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
		{
			if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
			{
				$sOrder .= "`".$aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."` ".
					($_GET['sSortDir_'.$i]==='asc' ? 'asc' : 'desc') .", ";
			}
		}
 
		$sOrder = substr_replace( $sOrder, "", -2 );
		if ( $sOrder == "ORDER BY" )
		{
			$sOrder = "";
		}
	}
 
	$sWhere = "";
 
	/* Individual column filtering */
	$sColumnWhere = "";
	for ( $i=0 ; $i<count($aColumns) ; $i++ )
	{	
		if ( $_GET['sSearch_'.$i] != "" )
		{
			$aWords = preg_split('/\s+/', $_GET['sSearch_'.$i]);
			$sColumnWhere .= "(";
			for ( $j=0 ; $j<count($aWords) ; $j++ )
			{
				if ( $aWords[$j] != "" )
				{
					$sColumnWhere .= "`".$aColumns[$i]."` = '".mysql_real_escape_string( $libelle[ $i ][ $aWords[$j] ] )."' OR ";
				}
			}
			$sColumnWhere = substr_replace( $sColumnWhere, "", -3 );
			$sColumnWhere .= ") AND ";
		}
		if ( $_GET['sStart_'.$i] != "" AND $_GET['sEnd_'.$i] != "" )
		{
			$sColumnWhere .= "(";
			$sColumnWhere .= "`".$aColumns[$i]."` >= '".mysql_real_escape_string( $_GET['sStart_'.$i] )."' AND `".$aColumns[$i]."` <= '".mysql_real_escape_string( $_GET['sEnd_'.$i] )."' ";
			$sColumnWhere .= ") AND ";
		}
	}
 
	if ( $sColumnWhere != "" ) {
		$sColumnWhere = substr_replace( $sColumnWhere, "", -5 );
		if ( $sWhere == "" ) {
			$sWhere = $sColumnWhere;
		} else {
			$sWhere .= " AND ".$sColumnWhere;
		}
	}
 
	if ( $sWhere != "" )
	{
		$sWhere = "WHERE ".$sWhere;
	}
 
 
	/*
	 * SQL queries
	 * Get data to display
	 */
	$sQuery = "
	 SELECT SQL_CALC_FOUND_ROWS `".str_replace(" , ", " ", implode("`, `", $aColumns))."` 
		FROM   $sTable
		$sWhere
		$sOrder
		$sLimit
		";
	$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
 
	/* Data set length after filtering */
	$sQuery = "
		SELECT FOUND_ROWS()
	";
	$rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
	$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
	$iFilteredTotal = $aResultFilterTotal[0];
 
	/* Total data set length */
	$sQuery = "
		SELECT COUNT(`".$sIndexColumn."`)
		FROM   $sTable
	";
	$rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
	$aResultTotal = mysql_fetch_array($rResultTotal);
	$iTotal = $aResultTotal[0];
 
 
	/*
	 * Output
	 */
	$output = array(
		"sEcho" => intval($_GET['sEcho']),
		"iTotalRecords" => $iTotal,
		"iTotalDisplayRecords" => $iFilteredTotal,
		"aaData" => array()
	);
 
	while ( $aRow = mysql_fetch_array( $rResult ) )
	{
				$on=0;
				$comparer = trim($aRow[ 'item_id' ]);
				if ($nbcomparer > 0) {
					for ($krow=0; $krow<$nbcomparer; $krow++) {
						if ($refcomparer[$krow] == $comparer) {
							array_splice($refcomparer,$krow,1);
							$nbcomparer--;
							$on=1;
							break;
						}
					}
				}
				$row = array();
				$row[] = "<div id='tag".$comparer."'><input id='comparer[".$comparer."]' type='checkbox' class='curseur' onclick='acomparer(".$comparer.");'"
				.($on==1?' CHECKED':'')."></div>";
				$row[] = trim($aRow[ 'cut' ]);
				$inter = trim($aRow[ 'carat' ]);
				$row[] = number_format($inter, 2, ',', ' ');
				$row[] = trim($aRow[ 'cut_grade' ]);
				$row[] = trim($aRow[ 'color' ]);
				$row[] = trim($aRow[ 'clarity' ]);
				if ($swCriteres[11] == "1") {
					$row[] = trim($aRow[ 'polish' ]);
				}
				if ($swCriteres[12] == "1") {
					$row[] = trim($aRow[ 'symmetry' ]);
				}
				if ($swCriteres[13] == "1") {
					$inter = trim($aRow[ 'depth' ]);
					if (floatval($inter)>0) {
						$row[] = number_format($inter, 2, ',', ' ');
					} else {
						$row[] = "";
					}
				}
				if ($swCriteres[14] == "1") {
					$inter = trim($aRow[ 'table' ]);
					if (floatval($inter)>0) {
						$row[] = number_format($inter, 2, ',', ' ');
					} else {
						$row[] = "";
					}
				}
				if ($swCriteres[15] == "1") {
					$row[] = trim($aRow[ 'fluo_intensity' ]);
				}
				if ($swCriteres[16] == "1") {
					$inter = trim($aRow[ 'price_per_carat_ht' ]);
					$row[] = number_format($inter, 0, ',', ' ');
				}
				if ($swCriteres[17] == "1") {
					$row[] = trim($aRow[ 'culet_size' ]);
				}
				if ($swCriteres[18] == "1") {
					$inter = trim($aRow[ 'length_width' ]);
					if (floatval($inter)>0) {
						$row[] = number_format($inter, 2, ',', ' ');
					} else {
						$row[] = "";
					}
				}
				$inter = trim($aRow[ 'delay' ]);
				if (floatval($inter) == 0) {
					$row[] = "nc";
				}
				if (floatval($inter) == 1) {
					$row[] = $inter." jour";
				}
				if (floatval($inter) > 1) {
					$row[] = $inter." jours";
				}
				$row[] = trim($aRow[ 'certificat' ]);
				$inter = trim($aRow[ 'total_price_ht' ]);
				$row[] = number_format($inter, 0, ',', ' ');
				$row[] = "<a href='#' onClick='envoiDetails(".trim($aRow[ 'item_id' ]).",\"".trim($aRow[ 'cut' ])."\",".trim($aRow[ 'carat' ]).");'><span class='voir'>D&eacute;tails</span></a>";
				$output['aaData'][] = $row;
	}
 
	echo json_encode( $output );
?>

Modifié par jytest (30 Sep 2013 - 10:29)
Suite à des corrections de code,
je viens de modifier les codes dans le message de base.

Merci d'avance pour votre aide :!