简体   繁体   English

尝试按列排序时,jQuery将行动态加载到表中不起作用

[英]Jquery dynamic loading of rows into a table not working when tried to sort by column

I am calling fixheadertable jquery during document ready. 我在准备文档期间正在调用fixheadertable jQuery。 After that we are adding dynamic rows to the table (id=test) based on some search results. 之后,我们根据一些搜索结果向表(id = test)添加动态行。 Code: 码:

$(document).ready(function(){
    $("#test").fixheadertable({
        caption : '',
        colratio : [50, 50, 50, 50]       
    });
}

Below code gets executed when we enter the search criteria. 当我们输入搜索条件时,将执行以下代码。 This will add the results into the table. 这会将结果添加到表中。

…………..
for ( var i = 0; i<size; i++) {
    $("#test").append('<tr><td>'+i.col1+'</td></tr><tr><td>'+i.col2+'</td></tr>');
}
………..
………….

Now if we click on the column header the data get vanished. 现在,如果单击列标题,数据将消失。 We need this to sort the table contents. 我们需要它来对表内容进行排序。 I have tried with some static data for the table and it worked fine. 我已经尝试了一些静态数据表,它工作正常。 But it is not working when we add rows after the page load is done. 但是,当页面加载完成后添加行时,它不起作用。

It looks like once the page is loaded the call to fixheadertable function in another jquery is not called. 看起来,一旦页面被加载,就不会调用另一个jquery中的fixheadertable函数。 Any idea? 任何想法? Please help. 请帮忙。

You may need to call the fixheadertable() wrapper method on the table element each time you update the data on the table, not only when the document ready. 每次更新表上的数据时,可能不仅在文档准备就绪时,都需要在表元素上调用fixheadertable()包装方法。

Try it....... 试试吧.......

function populateData(){
    .....................
    for ( var i = 0; i<size; i++) {
         $("#test").append('<tr><td>'+i.col1+'</td></tr><tr><td>'+i.col2+'</td></tr>');
    }

    $("#table").fixheadertable({
        caption : '',
        colratio : [50, 50, 50, 50]       
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM