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 :

Récupérer les valeurs des cases à cocher d'une tableau jQuery


Sujet :

jQuery

  1. #1
    Candidat au Club
    Inscrit en
    Février 2008
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 3
    Points : 4
    Points
    4
    Par défaut Récupérer les valeurs des cases à cocher d'une tableau jQuery
    Bonsoir,
    J'ai un tableau concu en jquery.L'une des colonnes du tableau est un checkbox.
    Le but est de pouvoir downloder les les lignes selectionnees par l'untilisateur.
    Mais je voudrais que vous m'aider a recuperer la colonne "Country" de chaque ligne selectionnee.

    Voici le code :


    Code html : 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
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="stylesheet" href="./script/jqwidgets/styles/jqx.base.css" type="text/css" />
        <script type="text/javascript" src="./script/scripts/jquery-1.8.2.min.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxcore.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxbuttons.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxscrollbar.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxmenu.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxcheckbox.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxlistbox.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxdropdownlist.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxgrid.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxgrid.pager.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxgrid.edit.js"></script>
        <script type="text/javascript" src="./script/jqwidgets/jqxgrid.selection.js"></script>	
        <script type="text/javascript" src="./script/jqwidgets/jqxdata.js"></script>	
        <script type="text/javascript" src="./script/scripts/gettheme.js"></script>
        <script type="text/javascript">
            function lbox(){
            $("input[type='checkbox']:checked").each(
              function() {
               console.log($(this).attr('id'));
             // });          
             }
        );
            
            }
            
            $(document).ready(function () {
                // prepare the data
                var theme = getDemoTheme();
            
                var source =
                {
                     datatype: "json",
                     datafields: [
                                             { name: 'Year', type: 'number' },
                                             { name: 'Country', type: 'string'},
                                             { name: 'Site', type: 'string'},
                                             { name: 'DataDomain', type: 'string'},
                                             { name: 'Project', type: 'string'},
                         { name: 'available', type: 'bool' },
                                             { name: 'Title', type: 'string'}
                    ],
     
                                url: 'all_data.php',
                                root: 'Rows',
                    cache: false,
                                    beforeprocessing: function(data)
                                    {               
                                            source.totalrecords = data[0].TotalRows;
                                    },
                                     updaterow: function (rowid, rowdata, commit) {
                        // synchronize with the server - send update command   
                        commit(true);
                    }
                };          
                            
                         var dataadapter = new $.jqx.dataAdapter(source);
                 var columnCheckBox = null;
                 var updatingCheckState = false;
     
                // initialize jqxGrid
                $("#jqxgrid").jqxGrid(
                {
                    width: 780,
                                source: dataadapter,
                    theme: theme,
                                autoheight: true,
                                    pageable: true,
                                    virtualmode: true,
                    editable: false,
                    enablehover: false,
                    selectionmode: 'none',
                                    rendergridrows: function()
                                    {
                                              return dataadapter.records;     
                                    },
                    columns: [
                                              //{ text: '', datafield: 'available', width: 40},  
                                             {text: '', datafield: 'available', columntype: 'checkbox', width: 40,
                          renderer: function () {
                              return '<div style="margin-left: 10px; margin-top: 5px;"></div>';
                          },
                          rendered: function (element) {
                              $(element).jqxCheckBox({ theme: theme, width: 16, height: 16, animationShowDelay: 0, animationHideDelay: 0 });
                              columnCheckBox = $(element);
                              $(element).on('change', function (event) {
                                  var checked = event.args.checked;
                                  if (checked == null || updatingCheckState) return;
                                  var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;
                                  $("#jqxgrid").jqxGrid('beginupdate');
     
                                  if (checked) {
                                      $("#jqxgrid").jqxGrid('selectallrows');
                                  }
                                  else if (checked == false) {
                                      $("#jqxgrid").jqxGrid('clearselection');
                                  }
     
                                  for (var i = 0; i < rowscount; i++) {
                                      $("#jqxgrid").jqxGrid('setcellvalue', i, 'available', event.args.checked);
                                  }
     
                                  $("#jqxgrid").jqxGrid('endupdate');
                              });
                          }
                      },                       
                                              { text: 'Year', datafield: 'Year', width: 60},
                          { text: 'Country', datafield: 'Country', width: 100 },
                          { text: 'Site', datafield: 'Site', width: 100 },
                          { text: 'Data Domain', datafield: 'DataDomain', width: 130 },
                          { text: 'Project', datafield: 'Project', width: 100 },
                          { text: 'Title', datafield: 'Title'}
                     
                                      ]
                });
                            
                    });
                     // select or unselect rows when the checkbox is checked or unchecked.
                 $("#jqxgrid").on('cellendedit', function (event) {
                     if (event.args.value) {
                         $("#jqxgrid").jqxGrid('selectrow', event.args.rowindex);
                     }
                     else {
                         $("#jqxgrid").jqxGrid('unselectrow', event.args.rowindex);
                     }
                     if (columnCheckBox) {
                         var selectedRowsCount = $("#jqxgrid").jqxGrid('getselectedrowindexes').length;
                         var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;
                         updatingCheckState = true;
                         if (selectedRowsCount == rowscount) {
                             $(columnCheckBox).jqxCheckBox('check')
                         }
                         else if (selectedRowsCount > 0) {
                             $(columnCheckBox).jqxCheckBox('indeterminate');
                         }
                         else {
                             $(columnCheckBox).jqxCheckBox('uncheck');
                         }
                         updatingCheckState = false;
                     }
                 });
     
        </script>
    </head>
    <body class='default'>
        <div id='jqxWidget' align="center"><br />
            <div id="jqxgrid"></div><br />
            <form name="form1" method="post" action="exedownload.php">
                <label>
                	<input type="checkbox" name="maincheck" id="maincheck" width="16" height="16" onClick="lbox()">
               		Select all files<br />
                </label>
                <input type="submit" name="downlobut" value="Download Selected Files">
            </form>
        </div>
    </body>
    </html>
    <!--serverpaging_data.php
    	#Include the connect.php file
    	include('connect.php');
    	#Connect to the database
    	//connection String
    	$connect = mysql_connect($hostname, $username, $password)
    	or die('Could not connect: ' . mysql_error());
    	//Select The database
    	$bool = mysql_select_db($database, $connect);
    	if ($bool === False){
    	   print "can't find $database";
    	}
    	// get data and store in a json array
     
    	$pagenum = $_GET['pagenum'];
    	$pagesize = $_GET['pagesize'];
    	$start = $pagenum * $pagesize;
    	$query = "SELECT SQL_CALC_FOUND_ROWS * FROM Customers LIMIT $start, $pagesize";
     
    	$result = mysql_query($query) or die("SQL Error 1: " . mysql_error());
    	$sql = "SELECT FOUND_ROWS() AS `found_rows`;";
    	$rows = mysql_query($sql);
    	$rows = mysql_fetch_assoc($rows);
    	$total_rows = $rows['found_rows'];
    	while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    		$customers[] = array(
    			'CompanyName' => $row['CompanyName'],
    			'ContactName' => $row['ContactName'],
    			'ContactTitle' => $row['ContactTitle'],
    			'Address' => $row['Address'],
    			'City' => $row['City'],
    			'Country' => $row['Country']
    		  );
    	}
        $data[] = array(
           'TotalRows' => $total_rows,
    	   'Rows' => $customers
    	);
    	echo json_encode($data);
     
    -->


    Merci

  2. #2
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 637
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 637
    Points : 66 662
    Points
    66 662
    Billets dans le blog
    1
    Ma page Developpez - Mon Blog Developpez
    Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
    Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
    Votre post est résolu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de Développez !

Discussions similaires

  1. Récupérer les valeurs de cases à cocher
    Par covin85 dans le forum Langage
    Réponses: 6
    Dernier message: 19/10/2009, 01h17
  2. [MySQL] Récupérer les valeurs des cases à cocher
    Par frankiboy dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 23/12/2008, 17h40
  3. Réponses: 15
    Dernier message: 21/12/2008, 19h31
  4. récupérer les noms des cases à cocher
    Par moimemessssssssss dans le forum Macros et VBA Excel
    Réponses: 11
    Dernier message: 16/06/2008, 20h54
  5. [MySQL] envoie les valeurs des cases à cocher
    Par soussan dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 19/06/2006, 17h18

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