簡體   English   中英

帶有 jQ​​uery DataTables 的單元格中的響應式擴展和 HTML 內容

[英]Responsive extension and HTML content in a cell with jQuery DataTables

我在我的應用程序中使用 jQuery DataTables。

我希望我的應用程序可以通過移動設備訪問。 我在我的應用程序中實現了http://jsfiddle.net/ryanoc/ebRXw/ 但是按鈕無法顯示。 數據如下所示: [object Object]

我在 jQuery DataTables 中使用render選項來顯示按鈕

"render": function(data, type, full ){
    var btn = '<a href="' + BASEURL + 'room/edit/'+ data.id +'" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i>&nbsp;Edit</a>&nbsp;';
    return btn;
},

解決方案

將以下選項添加到您的 DataTables 初始化代碼中。

responsive: {
    details: {
        type: 'inline',
        renderer: function (api, rowIdx) {
            var theRow = api.row(rowIdx);

            var data = api.cells(rowIdx, ':hidden').eq(0).map(function (cell) {
                var header = $(api.column(cell.column).header());

                return '<tr>' +
                    '<td><b>' +
                    header.text() + ':' +
                    '</b></td> ' +
                    '<td>' +
                    $( api.cell( cell ).node() ).html() +
                    '</td>' +
                    '</tr>';
            }).toArray().join('');

            return data ?
                $('<table/>').append(data) :
                false;
        }
    }
}

演示

有關代碼和演示,請參閱此 jsFiddle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM