简体   繁体   English

带有 jQ​​uery DataTables 的单元格中的响应式扩展和 HTML 内容

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

I use jQuery DataTables in my application.我在我的应用程序中使用 jQuery DataTables。

I want my application be accessed by mobile devices.我希望我的应用程序可以通过移动设备访问。 I implement http://jsfiddle.net/ryanoc/ebRXw/ in my application.我在我的应用程序中实现了http://jsfiddle.net/ryanoc/ebRXw/ But the button can not be displayed.但是按钮无法显示。 The data look like this : [object Object]数据如下所示: [object Object]

I use render option in jQuery DataTables to display the button我在 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;
},

SOLUTION解决方案

Add the following option to your DataTables initialization code.将以下选项添加到您的 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;
        }
    }
}

DEMO演示

See this jsFiddle for code and demonstration.有关代码和演示,请参阅此 jsFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM