IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

jQuery Discussion :

Changement de couleur sur ligne de tableau


Sujet :

jQuery

  1. #1
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut Changement de couleur sur ligne de tableau
    Bonjour,

    J'ai un tableau lié a une feuille de style css qui definit l'alternance des couleurs des lignes ainsi que la couleur rollover qui permet de colorer la ligne sur laquelle je survole.

    Avec Jquery j'ai 2 functions :
    une lors d'un click colore la cellule du tableau concernee
    un double click colore toute la ligne.

    Cela marche trs bien si je ne lie pas mon tableau à la feuille de style. Par contre si il est lié a la feullie de style le double click qui doit colorer la ligne ne marche pas. Je ne comprends pas pourquoi car la coloration de la cellule marche.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    $("#Tableau tr").dblclick(function() {
            if ($(this).hasClass("highlightRowOnClick")) {
                $(this).removeClass("highlightRowOnClick");
            } else {
                $(this).addClass("highlightRowOnClick");
            };
    Qq un a t il une idee ?

    Merci
    MCTS Microsoft.
    La conception : Prendre le temps pour gagner du temps.

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    207
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Novembre 2010
    Messages : 207
    Points : 344
    Points
    344
    Par défaut
    Lorsque tu mets le CSS de .highlightRowOnClick dans ton fichier CSS ça ne fonctionne pas ?
    Peux tu nous donner le CSS associé que tu as mis pour .highlightRowOnClick ?
    Sébastien Courjean
    Développeur Web
    scourjean@cyres.fr
    http://www.cyres.fr/

  3. #3
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    Non ca ne marche pas

    css :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    .highlightCell
    {
        background-color: yellow;
    }
    .highlightRowOnClick
    {
        background-color: red;
    }
    Js :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
    //To set the back ground color of gridview cell
    function HighlightCell(HTMLcontrol) {
        $(HTMLcontrol).click(function() {
        if ($(this).hasClass("Smart_GridView_highlightCell")) {
                $(this).removeClass("Smart_GridView_highlightCell");
        } else {
            $(this).addClass("Smart_GridView_highlightCell");
        }
        });
    }
     
    //To set the background color of gridview row
    function HighlightRowOnDblClick(HTMLcontrol) {
        $(HTMLcontrol + " tr").dblclick(function() {
            if ($(this).hasClass("highlightRowOnClick")) {
                $(this).removeClass("highlightRowOnClick");
            } else {
                $(this).addClass("highlightRowOnClick");
            };
        });
     
        $(HTMLcontrol + " td").dblclick(function() {
            $(this).removeClass("highlightCell");
        });
    }
    MCTS Microsoft.
    La conception : Prendre le temps pour gagner du temps.

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    207
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Novembre 2010
    Messages : 207
    Points : 344
    Points
    344
    Par défaut
    Ceci devrait te convenir je pense :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    <html>
    	<head>
    		<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
    		<style type="text/css">
    		.highlightCell
    		{
    			background-color: yellow;
    		}
    		.highlightRowOnClick
    		{
    			background-color: red;
    		}
    		</style>
    		<script type="text/javascript">
    		//To set the back ground color of gridview cell
    		function HighlightCell(HTMLcontrol) {
    			$(HTMLcontrol).click(function() {
    			if ($(this).hasClass("highlightCell")) {
    					$(this).removeClass("highlightCell");
    			} else {
    				$(this).addClass("highlightCell");
    			}
    			});
    		}
     
    		//To set the background color of gridview row
    		function HighlightRowOnDblClick(HTMLcontrol) {
    			$(HTMLcontrol + " tr").dblclick(function() {
    				$(HTMLcontrol + " td").each(function() {
    					$(this).removeClass("highlightCell");
    				});
    				if ($(this).hasClass("highlightRowOnClick")) {
    					$(this).removeClass("highlightRowOnClick");
    				} else {
    					$(this).addClass("highlightRowOnClick");
    				};
    			});
    		}
    		$(document).ready(function(){
    			HighlightCell("#t_1 td");
    			HighlightRowOnDblClick("#t_1");
    		});
    		</script>
    	</head>
    	<body>
    		<table id="t_1" border=1>
    			<tr>
    				<td>ligne 1 col 1</td>
    				<td>ligne 1 col 2</td>
    				<td>ligne 1 col 3</td>
    			</tr>
    			<tr>
    				<td>ligne 2 col 1</td>
    				<td>ligne 2 col 2</td>
    				<td>ligne 2 col 3</td>
    			</tr>
    		</table>
    	</body>
    </html>
    Sébastien Courjean
    Développeur Web
    scourjean@cyres.fr
    http://www.cyres.fr/

  5. #5
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    Cela vient du rollover

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    .GridView tr.normal:hover, .GridView tr.alternate:hover, .GridView tr.alternate:hover a, .GridView tr.normal:hover a
    {
    	background-color :#4282B5; 
    }
    Ca ne marche pas mieux
    MCTS Microsoft.
    La conception : Prendre le temps pour gagner du temps.

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    207
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Novembre 2010
    Messages : 207
    Points : 344
    Points
    344
    Par défaut
    tu as bien tester avec les 2 fonctions HighlightCell et HighlightRowOnDblClick de mon exemple ? Parce que moi ça marche de mon côté.
    Sébastien Courjean
    Développeur Web
    scourjean@cyres.fr
    http://www.cyres.fr/

  7. #7
    Membre confirmé
    Avatar de topolino
    Profil pro
    Inscrit en
    Juillet 2003
    Messages
    1 901
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2003
    Messages : 1 901
    Points : 637
    Points
    637
    Par défaut
    Voila ma solution.

    Merci a toi

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    function HighlightRowOnDblClick(HTMLcontrol) {
        $(HTMLcontrol + " tr").dblclick(function() {
            if ($(this).hasClass("Smart_GridView_highlightRowOnClick")) {
                $(this).removeClass("Smart_GridView_highlightRowOnClick");
                $(this).addClass($(this).attr('oldClass'));
            } else {
                $(this).attr("oldClass", $(this).attr('class'));
                $(this).removeClass($(this).attr('class'));
                $(this).addClass("Smart_GridView_highlightRowOnClick");
            };
        });
     
        $(HTMLcontrol + " td").dblclick(function() {
            $(this).removeClass("Smart_GridView_highlightCell");
        });
    }
    MCTS Microsoft.
    La conception : Prendre le temps pour gagner du temps.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 24/04/2008, 10h14
  2. [XSL/CSS] Changement de couleur une ligne sur deux
    Par FlyByck dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 08/09/2006, 20h20
  3. C# Changement de couleur des lignes d'une datagrid
    Par Depteam1 dans le forum Windows Forms
    Réponses: 1
    Dernier message: 11/06/2006, 10h31
  4. changement de couleur sur les lignes d'un tableau
    Par brasco06 dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 13/04/2006, 18h03
  5. Changement de couleurs sur enregistrements du DataGrid
    Par Bouassa dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 15/03/2006, 17h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo