Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2014
    Messaggi
    58

    Ordinamento tabella HTML con jquery

    Ragazzi praticamente non funziona il jquery, se schiaccio su quansiasi colonna non me lo mette in ordine!

    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta charset="utf-8">
      <meta http-equiv="Content-Type" content="text/html">
      <title>list seller</title>
      <link rel="stylesheet" type="text/css" media="all" href="css/styles.css">
      <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
      <script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
    </head>
    <body>
     <div id="wrapper">
        <table border="1" class="tablesorter" id="keywords" cellspacing="0" cellpadding="0" >
        <thead>
    <tr>
            <th><b>ID</b></th>
            <td><b>AVVIA TRATTATIVA</b></td>
            <td><b>STATO TRATTATIVA</b></td>
            <th><b>USERNAME</b></th>
           <th><b>NAZIONALITA'</b></th>
           <th><b>CAMBIO EURO</b></th>
           <th><b>QUANTITA' DISPONIBILE PER LA VENDITA</b></th>
           <th><b>METODI DI PAGAMENTI ACCETTATI</b></th>
           <th><b>STATUS</b></th>
       </tr>
       </thead>
    <tbody>
    <?php 
    session_start
    ();
    require_once(
    'lib/Users.class.php');
    $login = New Users;
    $login->access_denied();
    $db_username $login->get_username();
    $attiva "ATTIVA";

     
    // includiamo il file di configurazione
          
    include "db_config_reload.php";

    // seleziono i campi nelle varie tabelle
    $query mysql_query("SELECT seller.id, seller.username, seller.change, seller.amount, seller.paymetod, users.nazionalita FROM seller, users WHERE seller.username = users.username AND seller.status_trattativa = 0") or die(mysql_error());

    // scorro con un array la query e quindi i vari campi delle varie tabelle
    while($row mysql_fetch_array($query))

    {

        
    extract($row);

        
    $table .= "<tr>";
        
    $table .= (($i++)%== 0) ? "<tr style=\"background-color: #DDDDDD;\">" "<tr style=\"background-color: #FFFFFF;\">";
        
    $table .= "<form action=\"insert_ask.php\" method=\"post\">";
        
    $table .= "<input type=\"hidden\" name=\"insert_ask\" value=\"{$id};{$change};{$amount};
    {$paymetod};{$username};{$db_username}\" /> ";
        
    $table .= "<td> {$id} </td>";
        
    $table .= "<td> <input type=\"submit\" value=\"Avvia Trattativa\" onClick=\"return confirm('Trattativa id: $id, sicuro che &egrave questa la trattativa che vuoi avviare?');\"/> </td>";
        
    $table .= "</form>";
        
    $table .= "<td> {$status_trattativa} {$attiva} </td>";
        
    $table .= "<td> {$username} </td>";
        
    $table .= "<td> {$nazionalita} </td>";
        
    $table .= "<td> {$change} </td>";
        
    $table .= "<td> {$amount} </td>";
        
    $table .= "<td> {$paymetod} </td>";


        if(
    mysql_num_rows(mysql_query("SELECT username FROM users_online WHERE username = '".$username."'")) > 0)
        {
            
    $table .= "<td> ONLINE </td>";
        }
        else
        {
            
    $table .= "<td> OFFLINE </td>";
        }
        
    $table .= "</tr>";

    }

     echo 
    $table;
    ?>
    </tbody>
    </table>
     </div> 
    <script type="text/javascript">
    $(function(){
      $('#keywords').tablesorter(); 
    });
    </script>
    </body>
    </html>

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2014
    Messaggi
    58
    ho risolto cosi

    Codice PHP:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>
      <meta http-equiv="Content-Type" content="text/html">  <title>list seller</title>  <script type="text/javascript" src="js/Event.js"></script>  <script type="text/javascript" src="js/SortedTable.js"></script></head><body> <div id="wrapper">    <table border="1" class="sorted" id="table" cellspacing="0" cellpadding="0" >    <thead><tr>        <th><b>ID</b></th>        <td><b>AVVIA TRATTATIVA</b></td>        <td><b>STATO TRATTATIVA</b></td>        <th><b>USERNAME</b></th>       <th><b>NAZIONALITA'</b></th>       <th><b>CAMBIO EURO</b></th>       <th><b>QUANTITA' DISPONIBILE PER LA VENDITA</b></th>       <th><b>METODI DI PAGAMENTI ACCETTATI</b></th>       <th><b>STATUS</b></th>   </tr>   </thead><tbody><?php session_start();require_once('lib/Users.class.php');$login = New Users;$login->access_denied();$db_username $login->get_username();$attiva "ATTIVA";
     
    // includiamo il file di configurazione      include "db_config_reload.php";
    // seleziono i campi nelle varie tabelle$query = mysql_query("SELECT seller.id, seller.username, seller.change, seller.amount, seller.paymetod, users.nazionalita FROM seller, users WHERE seller.username = users.username AND seller.status_trattativa = 0") or die(mysql_error());
    // scorro con un array la query e quindi i vari campi delle varie tabellewhile($row = mysql_fetch_array($query))
    {
        
    extract($row);
        
    $table .= "<tr>";    $table .= (($i++)%== 0) ? "<tr style=\"background-color: #DDDDDD;\">" "<tr style=\"background-color: #FFFFFF;\">";    $table .= "<form action=\"insert_ask.php\" method=\"post\">";    $table .= "<input type=\"hidden\" name=\"insert_ask\" value=\"{$id};{$change};{$amount};{$paymetod};{$username};{$db_username}\" /> ";    $table .= "<td> {$id} </td>";    $table .= "<td> <input type=\"submit\" value=\"Avvia Trattativa\" onClick=\"return confirm('Trattativa id: $id, sicuro che &egrave questa la trattativa che vuoi avviare?');\"/> </td>";    $table .= "</form>";    $table .= "<td> {$status_trattativa} {$attiva} </td>";    $table .= "<td> {$username} </td>";    $table .= "<td> {$nazionalita} </td>";    $table .= "<td> {$change} </td>";    $table .= "<td> {$amount} </td>";    $table .= "<td> {$paymetod} </td>";

        if(
    mysql_num_rows(mysql_query("SELECT username FROM users_online WHERE username = '".$username."'")) > 0)    {        $table .= "<td> ONLINE </td>";    }    else    {        $table .= "<td> OFFLINE </td>";    }    $table .= "</tr>";
    }
     echo 
    $table;?></tbody></table> </div> <script type="text/javascript">onload = function() {var table = new SortedTable();}</script></body></html>
    ora se volessi fare in modo che mi escano le righe alternate una con colori differenti tramite javascipt?
    io utilizzo il metodo con html che vedete sopra per averle ma ua volta che prova a mettere in ordine naturalmente non si ha piu l'effetto!

  3. #3
    Utente di HTML.it
    Registrato dal
    Dec 2013
    Messaggi
    228
    scriviti una funzione jQuery
    PSEUDOCODICE

    (FOR i=0...i<numerorighe...)
    IF(i%2==0)//se pari
    $('#IDtabella').child('tr').toggleClass('rigapari' ,true)
    $('#IDtabella').child('tr').toggleClass('rigadispa ri',false)
    ELSE
    l'esatto opposto
    ENDIF

  4. #4
    Utente di HTML.it
    Registrato dal
    Feb 2014
    Messaggi
    58
    non ho capito, se gentilmente potresti integrrlo nel mio scipt!
    Kmq ho visto che ho sistemato pero non mi mette in ordine crescente e decrescente le varie colonne numero e in ordine alfabetica le coloonne stringa! Devo dichiararlo qui vero SortedTable()? la sintassi qual'è??

  5. #5
    Utente di HTML.it
    Registrato dal
    Dec 2013
    Messaggi
    228
    no, perché bisogna perderci troppo tempo a studiarsi come funziona il plugin tablesorter per capire quando va lanciato lo script. scusa.

  6. #6
    Utente di HTML.it L'avatar di abellos
    Registrato dal
    Feb 2002
    Messaggi
    431
    Ciao puoi mettere solamente la parte html senza il php che cosi non e' molto leggibile per chi non conosce il php
    Da un grande potere derivano grandi responsabilità

  7. #7
    Per il colore alternato delle righe, utilizza i css e tr:nth-child(even) e tr:nth-child(odd), che ti permettono di non preoccuparti per nulla della cosa lato javascript.
    "Le uniche cose che sbagli sono quelle che non provi a fare."
    Atipica

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.