斗士狗 2016-11-26 18:49 采纳率: 0%
浏览 23

JQM响应表问题

<table data-role="table" id="statement" data-mode="columntoggle" class="ui-body-d ui-shadow table-stripe ui-responsive" data-column-btn-theme="b" data-column-btn-text="Headings" data-column-popup-theme="a">
 <thead>
   <tr class="ui-bar-d">
    <th data-priority="1">Category</th>
    <th data-priority="5">Date</th>
    <th data-priority="1">Debit</th>
    <th data-priority="1">Credit</th>
    <th data-priority="1">Balance</th>
   </tr>
 </thead>
<tbody>
</tbody>
</table>

Below is how i populate the table with AJAX.

$.each(data, function(index, item) {
      $("#statement").append("<tr>"+
                             "<td>" + item.category + "</td>"+
                             "<td>" + item.transaction_date + "</td>"+
                             "<td>" + item.debit + "</td>"+
                             "<td>" + item.credit + "</td>"+
                             "<td>" + item.Balance + "</td>"+
                             "</tr>");
        });

The code works fine, but the problem i have is that when i select the columns to hide, only the th in the thead disappears, but the td in the tbody does not. In other words, the effect only happens on the head section and not on the body section. The tbody section remains unchanged while the thead section the column disappears.

I also noticed that when i populate the table manually without using AJAX, when i choose the column to hide, the effect happens on both the thead section and the tbody section. That means it works fine when i populate the table manually without using AJAX. I think the problem might be with the DOM.

Can anyone help me out how to sort out this problem.

  • 写回答

1条回答 默认 最新

  • 喵-见缝插针 2016-11-28 12:52
    关注

    First, append the new rows to the table body, not the table Second, after appending the rows, tell the table widget to rebuild

      $.each(data, function(index, item) {
        $("#statement tbody").append("<tr>"+
                                     "<td>" + item.category + "</td>"+
                                     "<td>" + item.transaction_date + "</td>"+
                                     "<td>" + item.debit + "</td>"+
                                     "<td>" + item.credit + "</td>"+
                                     "<td>" + item.Balance + "</td>"+
                                     "</tr>");
      });
      $("#statement").table( "rebuild" );
    

    DEMO

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置