【问题标题】:Adding Table Header and Footer with Jquery使用 Jquery 添加表格页眉和页脚
【发布时间】:2012-12-18 05:48:37
【问题描述】:

我有一个组合框

  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);
        });

【问题讨论】:

  • k.. 这是可能的。你能告诉我 ctrl.dropDown.$items 的数据吗?以及您如何需要 html 中的最终输出...
  • 这里没有声明e数据的值,你能显示完整的代码吗?
  • 你可以将你的完整代码粘贴到jsfiddle.net,保存并粘贴评论中的链接...

标签: jquery html-table footer


【解决方案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(''));

【讨论】:

  • 我需要 ctrl.dropDown.$items 和 e 的值。那么你的最终输出 html 应该如何处理该数据。以便我可以为您提供代码。
猜你喜欢
  • 2010-12-03
  • 2017-06-14
  • 2013-10-24
  • 1970-01-01
  • 2013-09-30
  • 1970-01-01
  • 2020-01-02
  • 1970-01-01
  • 2012-04-09
相关资源
最近更新 更多