Problemi con oggetto DataTable…
- Questo topic ha 1 risposta, 2 partecipanti ed è stato aggiornato l'ultima volta 7 anni, 7 mesi fa da sanzweb.
- AutorePost
- 6 Maggio 2016 alle 09:39 #6960crileonePartecipante
Ciao ragazzi,
carico da una tabella SQL dei recordset in un oggetto DataTable con questa pagina:$(document).ready(function() { // Setup - add a text input to each footer cell $('#example tfoot th').each( function () { var title = $('#example thead th').eq( $(this).index() ).text(); $(this).html( '<input type="text" placeholder="Search '+title+'" />' ); } ); // DataTable var table = $('#example').DataTable({ //"order": [[ 3, "desc" ]] }); // Apply the search table.columns().every( function () { var that = this; $( 'input', this.footer() ).on( 'keyup change', function () { if ( that.search() !== this.value ) { that .search( this.value ) .draw(); } } ); } ); } );
Questa la tabella HTML:
<table id="example" class=display cellspacing="0"> <thead> <tr> <th ></th> <th ><font face="Arial" size="2">Inserita da</font></th> <th ><font face="Arial" size="2">Operatore</font></th> <th ><font face="Arial" size="2">ID</font></th> <th width="15" > </th> <th width="15" > </th> <th ><font face="Arial" size="2">Data Inserimento</font></th> <th ><font face="Arial" size="2">Amministratore</font></font></th> <th ><font face="Arial" size="2">Codice Distinta</font></font></th> <th ><font face="Arial" size="2">Mittente</font></th> <th ><font face="Arial" size="2">Destinatario</font></th> <th ><font face="Arial" size="2">Numero Raccomandata</font></th> <th ><font face="Arial" size="2">Stato</font></th> <th ><font face="Arial" size="2">Costo Spedizione</font></th> <th ><font face="Arial" size="2">Data Consegna</font></th> <th ><font face="Arial" size="2">Data Giacenza</font></th> <th ><font face="Arial" size="2">Corriere</font></th> </tr> </thead> <tfoot> <tr> <th ></th> <th ><font face="Arial" size="2">Inserita da</font></th> <th ><font face="Arial" size="2">Operatore</font></th> <th><font face="Arial" size="2">ID</font></th> <th width="15" > </th> <th width="15" > </th> <th ><font face="Arial" size="2">Data Inserimento</font></th> <th ><font face="Arial" size="2">Amministratore</font></font></th> <th ><font face="Arial" size="2">Codice Distinta</font></font></th> <th ><font face="Arial" size="2">Mittente</font></th> <th ><font face="Arial" size="2">Destinatario</font></th> <th ><font face="Arial" size="2">Numero Raccomandata</font></th> <th ><font face="Arial" size="2">Stato</font></th> <th ><font face="Arial" size="2">Costo Spedizione</font></th> <th ><font face="Arial" size="2">Data Consegna</font></th> <th ><font face="Arial" size="2">Data Giacenza</font></th> <th ><font face="Arial" size="2">Corriere</font></th> </tr> </tfoot> <tbody> <% While Not Rs.EOF Set rs2 = server.CreateObject("adodb.recordset") Set conn2 = server.CreateObject("adodb.connection") conn2.ConnectionString = "Provider=SQLOLEDB.1;Password=9dcz2d6z28;Persist Security Info=false;User ID=MSSql115073;CommandTimeOut=360;Initial Catalog=MSSql115073;Data Source=62.149.153.53" Sql2="select Cognome+' '+Nome AS Operatore from Operatori where ID='"&Rs.Fields("IDOperatore")&"' " conn2.open rs2.open Sql2, conn2, 3, 3 Operatore=Rs2.Fields("Operatore") Rs2.Close Conn2.Close %> <tr> <% If Rs.Fields("Stato")="Consegnato al Destinatario" Then Colore="#3ff835" ElseIf Rs.Fields("Stato")="Giacenza" Then Colore="#faf3a5" ElseIf Rs.Fields("Stato")="Restituito al Mittente" Then Colore="#fa263a" ElseIf Rs.Fields("Stato")="Destinatario non Presente" Then Colore="#f5be29" ElseIf Rs.Fields("Stato")="Consegnato al Corriere" Then Colore="#caf9fa" ElseIf Rs.Fields("Stato")="Nuovo" Then Colore="#e7e5e5" End If %> <td> <input type="checkbox" name="Spunta" value="<% =rs.Fields("NumeroRaccomandata") %>"> </td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" ><% =Rs.Fields("TipologiaUtente") %></font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" ><% =Operatore %></font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" ><% =Rs.Fields("ID") %></font></td> <!--<td width="15" bgcolor="<% =Colore %>">"></td>--> <!--<td width="15" bgcolor="<% =Colore %>">"></td>--> <td width="15" bgcolor="<% =Colore %>">')"></td> <% Dim cartella, fso, apri, file, alfa, i, arr_alfa cartella = "files/files" Set fso = CreateObject("Scripting.FileSystemObject") Set apri = fso.GetFolder(Server.MapPath(cartella)) alfa = "a b c d e f g h i j k l m n o p q r s t u v w x y z" arr_alfa = Split(alfa, " ") int i=0 dim nomefile For Each file In apri.Files separ= InStr(file.name, "_") 'separ = separ-1 If Left(file.name, 15) = Rs.Fields("NumeroRaccomandata") or Left(file.name, 14) = Rs.Fields("NumeroRaccomandata") Then 'Response.Write file.name & "<br>" i=i+1 End If nomefile= nomefile + file.name Next if i>0 then %> <!--<td width="15" bgcolor="<% =Colore %>">"></td>--> <td width="15" bgcolor="<% =Colore %>">')"></td> <% else %> <td width="15" bgcolor="<% =Colore %>"></td> <% end if 'response.Write(i) i=0 Set fso = Nothing Set apri = Nothing %> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" ><% =Rs.Fields("DataIns") %></font></td> <% CodiceDistinta=Rs.Fields("CodiceDistinta") set cnn = CreateObject("ADODB.Connection") set RsAmm = CreateObject("ADODB.Recordset") set cmd = CreateObject("ADODB.Command") cnn.open "Provider=SQLOLEDB.1;Password=9dcz2d6z28;Persist Security Info=True;User ID=MSSql115073;Initial Catalog=MSSql115073;Fonte dati=PASQLSRV;Network Address=62.149.153.53" cmd.CommandTimeout = 0 cmd.ActiveConnection = cnn cmd.CommandText="EXEC sp_TrovaAmministratore '"&CodiceDistinta&"' " cmd.Execute RsAmm.Open cmd If Not RsAmm.EOF Then Amministratore=RsAmm.Fields("Amministratore") Else Amministratore="-" End If RsAmm.Close cnn.Close %> <td><font face="Arial" size="2" ><% =Amministratore %></font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" ><% =Rs.Fields("CodiceDistinta") %></font></font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" ><% =Rs.Fields("Mittente") %></font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" ><% =Rs.Fields("Destinatario") %></font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" >"><% =Rs.Fields("NumeroRaccomandata") %></font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" ><% =Rs.Fields("Stato") %></font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" ><% =FormatCurrency(Rs.Fields("CostoSpedizione")) %></font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2" > <% If Rs.Fields("DataConsegna")="01/01/1900" Then Response.Write("-") Else Response.Write(Rs.Fields("DataConsegna")) End If %> </font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2"> <% If Rs.Fields("DataGiacenza")="01/01/1900" Then Response.Write("-") Else Response.Write(Rs.Fields("DataGiacenza")) End If %> </font></td> <td bgcolor="<% =Colore %>"><font face="Arial" size="2"><% =Rs.Fields("Corriere") %></font></td> </tr> <% Rs.Movenext WEnd Rs.Close conn.Close %> <tbody> </table>
Il problema è che raggiunti i 500 record, nella tabella SQL, la pagina impiega un sacco di tempo (quasi 50 secondi) per caricare l’oggetto e mostrarmi il risultato.
Ovviamente i tempi si riferiscono ad una connessione Fibra che si attesta a 31 Mb/s.
Come posso velocizzare il load della pagina?
Grazie e tutti e Buona Giornata24 Agosto 2016 alle 17:18 #6994sanzwebPartecipanteCiao crileone,
potresti provare a caricare i record usando nella query la clausola LIMIT e impostarla tipo a 50 record per volta, e poi avanzare con i risultati con 2 pulsanti <<PREC SUCC>>.
La clausola LIMIT limita il numero di righe che saranno restituite. Se usata con un solo parametro, indica il numero massimo di righe restituite a partire dalla prima. Se usata con due parametri, il primo indica la riga di partenza (la prima riga equivale a 0), mentre il secondo è il numero massimo di righe.
Utilizzando quindi degli indici opportuni puoi regolare la visualizzazione dei record facendo attenzione a quando arrivi a 0 per il limite inferiore e al limite superiore (recordCount)
In questo modo penso si riesca a risparmiare abbastanza tempo nel caricamento dei dati.
non so se è quello che cercavi…ma ci ho provato
saluti
Sanzweb
- AutorePost
- Devi essere connesso per rispondere a questo topic.