早上好,我在React js
应用中运行服务器端数据表脚本,并设法使其显示reactstrap
按钮,如下所示:
"columnDefs": [
{
"targets": 4,
"data": null,
"createdCell": function (td, cellData, rowData, row, col){
return _this.datatableButtons(td);
}
}
]
datatableButtons(td) {
ReactDOM.render(
<ButtonGroup>
<Button className="btn-icon btn-icon-only" color="primary" title="Edit Branch">
<i className="pe-7s-pen btn-icon-wrapper"> </i>
</Button>
<Button className="btn-icon btn-icon-only" color="warning" title="Activate Branch">
<i className="pe-7s-switch btn-icon-wrapper"> </i>
</Button>
<Button className="btn-icon btn-icon-only" color="danger" title="Delete Branch" onClick={() => this.deleteBranch()}>
<i className="pe-7s-trash btn-icon-wrapper"> </i>
</Button>
</ButtonGroup>, td);
}
这很棒,但是只要我对其响应式视图进行测试,它就不再显示按钮,而是在所有隐藏表行上显示[object Object]
。我很想知道是否有解决方案。
答案 0 :(得分:1)
我设法通过添加以下代码来解决它:
'responsive': {
details: {
renderer: function ( api, rowIdx, columns ) {
var data = $.map( columns, function ( col, i ) {
if(col.columnIndex == 3) {
var result = '';
if (col.hidden) {
result = '<tr data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+
'<td>'+
'<ul class="dtr-details">'+
'<li>'+
'<span class="dtr-title">'+col.title+':'+'</span> ';
if($.trim(col.data.activate).toUpperCase() == 'ACTIVE')
result += '<label class="switch"><input type="checkbox" name="active" value="active" checked /><span class="slider"></span></label>';
else
result += '<label class="switch"><input type="checkbox" name="active" value="active" /><span class="slider"></span></label>';
result += '</li>'+
'</ul>'+
'</td>'+
'</tr>';
}
return result;
}else if(col.columnIndex == 4) {
return col.hidden ?
'<tr data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+
'<td>'+
'<ul class="dtr-details">'+
'<li>'+
'<span class="dtr-title">'+col.title+':'+'</span> '+
'<div class="btn-group">'+
'<button type="button" class="btn btn-icon btn-icon-only btn-primary" title="Edit Branch"><i class="pe-7s-pen btn-icon-wrapper"> </i></button>'+
'<button type="button" class="btn btn-icon btn-icon-only btn-danger delete_branch" id="del_'+col.rowIndex+'"><i class="pe-7s-trash btn-icon-wrapper"> </i></button>'+
'</div>'+
'</li>'+
'</ul>'+
'</td>'+
'</tr>' :
'';
} else {
return col.hidden ?
'<tr data-dt-row="'+col.rowIndex+'" data-dt-column="'+col.columnIndex+'">'+
'<td>'+
'<ul class="dtr-details">'+
'<li>'+
'<span class="dtr-title">'+col.title+':'+'</span>'+
'<span class="dtr-data">'+col.data+'</span>'+
'</li>'+
'</ul>'+
'</td>'+
'</tr>' :
'';
}
} ).join('');
return data ?
$('<table/>').append( data ) :
false;
}
}
}
我改用香草靴