简体   繁体   中英

Responsive extension and HTML content in a cell with jQuery DataTables

I use jQuery DataTables in my application.

I want my application be accessed by mobile devices. I implement http://jsfiddle.net/ryanoc/ebRXw/ in my application. But the button can not be displayed. The data look like this : [object Object]

I use render option in jQuery DataTables to display the button

"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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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