2013-01-03 115 views
0

我有一个组合框,其添加表页眉和页脚与jQuery

  1. 生成数据
  2. 结合组合框为表格

我要添加页眉和页脚的多列组合框,并试图冻结页眉和页脚。请建议

 $.each(ctrl.dropDown.$items, function (idx, item) { 
      var header = '<thead><tr><td>Account Name</td><td>Account Number</td><td>Agreement Number</td></tr></thead>'; 

      var footer = '<tr><td colspan=3>'+idx+' items</td></tr>'; 
      $(item).empty(); 
      if (idx == 0) { 
       $(item).prepend(header); 
      } 
      var tr = $('<tr/>'); 
      $.each(e.displayFields, function (dfdx, displayField) { 
       var $td = $('<td/>').text(e.data[idx][displayField.fieldName]); 
       //alert(e.data[idx][displayField.fieldName]); 
       if (displayField.style != undefined) { 
        $td.attr('style', displayField.style); 
       } 
       $td.css('white-space', 'nowrap'); 
       tr.append($td); 
      }); 
      var table = $('<table/>') 
       .attr({ 
        'id':'tblComboList', 
        'cellpadding': '0px', 
        'cellspacing': '0px', 
        'width':'319px' 
       }); 

      table.append(tr); 
      if(idx ==0){ 
       table.prepend(header); //adding header but it is not freezed above table 
      } 
      $(item).append(table); 
     }); 
+0

K。。这是可能的。你能告诉我ctrl.dropDown。$ items的数据吗?以及如何ü需要HTML中的最终输出... – Thulasiram

+0

电子数据的价值是不是在这里宣布可以显示完整的代码? – Thulasiram

+0

你可以在http://jsfiddle.net/粘贴你的完整代码,保存并粘贴链接评论... – Thulasiram

回答

1
$('body').empty(); 

var tempDataMain = []; 
tempDataMain.push($('<div />').append($('<table />').attr({ 'id': 'tblComboList', 'cellpadding': '0px', 'cellspacing': '0px', 'width': '319px' })).html()); 
tempDataMain.push('<thead><tr><td>Account Name</td><td>Account Number</td><td>Agreement Number</td></tr></thead>'); 
tempDataMain.push('<tbody>'); 

$.each(ctrl.dropDown.$items, function (i, item) { 
    //tempDataMain.push('<tr><td colspan="3">' + i + ' items</td></tr>'); 

    var $tr = $('<tr/>'); 
    $.each(e.displayFields, function (j, displayField) { 
     var $td = $('<td/>').text(e.data[i][displayField.fieldName]); 

     if (displayField.style != undefined && displayField.style != null) { 
      $td.attr('style', displayField.style); 
     } 
     $tr.append($td.css('white-space', 'nowrap')); 
    }); 

    tempDataMain.push($('<div />').append($tr).html()); 
}); 

tempDataMain.push('</tbody>'); 
tempDataMain.push('</table>'); 

$('body').append(tempDataMain.join('')); 
+0

我需要ctrl.dropDown。$ items和e的值。那么你的最终输出html应该如何处理这些数据。以便我可以为您提供代码。 – Thulasiram