0

当我在我的数据表中应用过滤器时,我调用了在表上加载数据的相同函数,但这次它没有样式、查找框、prev-next 出现......这是我的代码:

<script type="text/javascript">
        $(document).ready(function() {
            $('#dataTable').dataTable();
        } );             
        // ----este array vendria de una consulta sql----           
        miArray = [[11,22,33,44,55,"22/11/2012",99,86,99,1010,1111],[11,22,33,44,55,"11/06/2011",77,88,99,1010,1111],[11,22,33,44,55,"11/06/2011",77,88,99,1010,1111],[11,22,33,44,55,"11/06/2011",77,88,99,1010,1111],[11,22,33,44,55,"11/06/2011",77,88,99,1010,1111],[11,22,33,44,55,"11/06/2011",77,88,99,1010,1111],[11,22,33,44,55,"11/06/2011",77,88,99,1010,1111],[11,22,33,44,55,"11/06/2011",77,88,99,1010,1111],[11,22,33,44,55,"11/06/2011",77,88,99,1010,1111]];

        function cargar(miArray){
            document.getElementById("divTabla").innerHTML = ""
            var tabla= "<table name='tabla1' id='dataTable'><thead><tr><th>Tipo de documento</th><th>Tipo de documento</th><th>Tipo de documento</th><th>Codigo de documento</th><th>Descripcion de documento</th><th>Fecha de documento</th><th>Codigo de proveedor</th><th>Descripcion de proveedor</th><th>Importe</th><th>Importe IVA</th><th>Total a pagar</th></tr></thead><tbody>"
                for (i=0;i<miArray.length;i++){ 
                        tabla = tabla + '<tr>'
                    for (j=0;j<miArray[i].length;j++){              
                        tabla = tabla +'<td></td>'                      
                    }   
                    tabla = tabla + '</tr>'     
                }
                tabla = tabla +'</tbody></table>'                   
                document.getElementById("divTabla").innerHTML = tabla               
                h=1
                for (i=0;i<miArray.length;i++){
                    for (j=0;j<miArray[i].length;j++){          
                        document.getElementById("dataTable").rows[h].cells[j].innerHTML = miArray[i][j]         
                    }   
                h++ 
                }       
        }
        function filtroP(){
            arrayP = []
            var h=0;
            for (i=0;i<miArray.length;i++){
                if (miArray[i][6]== document.form1.prov.value){
                    arrayP[h]=miArray[i]
                    h++
                }
            }
            alert(arrayP)
            cargar(arrayP); 
        }               
    </script>       
4

1 回答 1

0

cargar看起来您在设置时将表拆开并读取它innerHtml。如果您直接更改表的结构,您可能需要重新调用 Datatables 为新表重新初始化它。

我不完全确定您的代码应该做什么,但考虑使用数据表中fnFilter已有的函数来进行过滤。见http://datatables.net/api#fnFilter

您也可能喜欢fnDeleteRow http://datatables.net/api#fnDeleteRow

于 2012-04-24T03:38:26.007 回答