Visualizzazione dei risultati da 1 a 3 su 3

Discussione: DOM & Tabelle

  1. #1
    Utente di HTML.it L'avatar di antos
    Registrato dal
    Feb 2001
    Messaggi
    3,581

    DOM & Tabelle

    Salve a tutti, ho un grosso problema con la generazione tramite DOM di una tabella.
    in pratica quando le colonne diventano troppe (circa 20 o +) lo script tende a bloccare il browser nonostante ci siano poche righe.
    ho provato ad usare dove possibile, (visto che IE non supporta innerHTML per i tag tr,tbody,table) "innerHTML" o documentFragment
    ci sono soluzioni per migliorare le prestazioni per la generazione di tabelle tramite DOM?

  2. #2
    Prendela con le molle perchè è una prima bozza
    ad ogni modo guarda se ti viene l'ispirazione

    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
    >
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <
    script language="JavaScript" type="text/JavaScript">
    function 
    _createElement(el,obj){
        var 
    _eldocument.createElement(el);
        for(var 
    prop in obj){
            if(
    prop=='class'){
                
    //fix ie behaviour
                
    _el.classNameobj[prop];
            }
             
    _el.setAttribute(prop,obj[prop]);
        }
        return 
    _el;
    };
    function 
    _createTextNode(text){
        return 
    document.createTextNode(text);
    };
    function 
    Grid(target){
        
    this._targettarget;
        
    this.display=function(){
               
    this._table.cellSpacingthis._cellSpacing;
               
    this._table.cellPaddingthis._cellPadding;
            
    this._target.appendChild(this._table);
        }
        
    this.setTable= function(cs,cp,obj){
            
    this._table_createElement('table',obj);
            
    this._cellSpacing cs;
            
    this._cellPadding cp;
        }
        
    this.setHeader=function(headers){
            
    this._theaddocument.createElement('thead');
            var 
    _trdocument.createElement('tr');
            for (var 
    0headers.lengthi++){
                var 
    _th document.createElement('th');
                
    _th.appendChild(document.createTextNode(headers[i]));
                
    _tr.appendChild(_th);
            }
            
    this._thead.appendChild(_tr);
            
    this._table.appendChild(this._thead);
       }
        
    this.setBody=function(data){
            
    this._tbodydocument.createElement('tbody');
            for (var 
    0data.lengthi++){
                var 
    _trdocument.createElement('tr');
                for(var 
    prop in data[i]){
                    var 
    _td document.createElement('td');
                    
    _td.appendChild(document.createTextNode(data[i][prop]));
                    
    _tr.appendChild(_td);
                }
                
    this._tbody.appendChild(_tr);
            }
            
    this._table.appendChild(this._tbody);
       }
        
    this.build=function(){
            
        }
    }
    window.onload=function(){
     var 
    mybody =document.getElementsByTagName("body")[0];
    var 
    _table= new Grid(mybody)
    _table.setTable(5,5,{'with':'500','class':'mytable'});
    _table.setHeader(['ID','Title','Description']);
    var 
    p= [{'id':1,'title':'Hello','description':'hello descr'},{'id':1,'title':'Hello2','description':'hello2 descr'}];
    _table.setBody(p);
    //_table.build();
    _table.display();

    }
    </script>

    </head>

    <body>
    </body>
    </html> 
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #3
    Utente di HTML.it L'avatar di antos
    Registrato dal
    Feb 2001
    Messaggi
    3,581
    grazie per l'interesse e lo script è di sicuro aiuto...
    il problema comunque non è in COME generare la tabella (o modificarla al volo), il problema è che al crescere della tabella rischio di bloccare il browser

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.