具有隐藏列的表,当可见时,它们之间存在间隙

时间:2014-08-08 04:59:51

标签: javascript

我有一个只有一个可见列的表。其他列标题是在下拉列表中侦听。 从下拉列表中选择值时,该列将变为可见。 但是,如果选择了两个不相邻的列并使其可见,则它们具有间隙(存在于它们之间的列并且是隐藏的)。 任何人都可以帮助我摆脱可见列之间的差距吗? 感谢

Velocity中TableTable的代码:

<table id="table_datagrid" class="ma-calendar-table" >

      <thead>
        <tr>
         <th class="sorting calendar_th" style="word-wrap:break-word; white-space: pre;">Test</th>

           #foreach($col in $columns)
               #if($col != 'Test')
                  <th class="sorting calendar_th column_${velocityCount}" style="word-wrap:break-word; max-width:130px; white-space: normal; visibility: hidden;">$col</th>
               #end
           #end

        </tr>
      </thead>

      <tbody>
       #foreach($row in $result)
          <tr>
            <td class="metric_name"> $row.get('Test')<br>&nbsp; </td>

            #foreach($colm in $columns)
              #if($colm != 'Test')

                #if( !$row.get($colm) || $row.get($colm)=='')
                  #set($val = '')
                #else
                  #set($val = $row.get($colm))
                #end                  

                <td class="metric_value column_${velocityCount}" style=" max-width:130px; visibility: hidden;">$val</td>
                #set($val = '')
              #end
            #end

          </tr>
        #end              
    </tbody>
  </table>

JavaScript代码:

$('#status_sel').on("change", function() {

    var sel_wloads = $('#status_sel').select2("val");           
    for (var i = 0; i < sel_wloads.length; i++) {

        var name = 'column_'+sel_wloads[i];
        console.log(name);

        $('.'+name).each(function(){

            console.log($(this).text());
            $(this).css("visibility","visible");
        });
    }

});

},

1 个答案:

答案 0 :(得分:0)

使用cellpadding =“0”cellspacing =“0”

我认为它会对你有所帮助。如果你仍然遇到问题,请粘贴表格中的一些虚拟数据,这样可能会更清楚