我正在使用带有ajax数据请求(json格式)的datatables和动态列加载。这是我的实际代码:
var tableData;
var tableName='#iuprTable';
$(document).ready(function (){
jQuery.ajax({
type : "GET",
url : "table/"+document.getElementById("hiddenIdCar").value,
headers: {'Content-Type': 'application/json'},
beforeSend: function() {
waitingModal.showPleaseWait();
},
success: function(data,status,xhr){
//No exception occurred
if(data.success){
tableData = data.result;
$.each(tableData.columns, function (k, colObj) {
var str = '<th data-html="true" data-toggle="tooltip" title="<b>NAME</b>:'+ colObj.parName + '<br><b>DESCRIPTION</b>:' + colObj.description + '<br><b>NOTE</b>: ' + colObj.note + '"></i>' + colObj.parName + '</th>';
$(str).appendTo(tableName+'>thead>tr');
});
} else {
waitingModal.hidePleaseWait();
notifyMessage(data.result, 'error');
}
},
error: function(xhr,status,e){
window.location.href = "/500";
}
}).complete(function() {
//initialize datatable
if ( ! $.fn.DataTable.isDataTable( tableName ) ) {
var iuprTable = $(tableName).DataTable({
scrollCollapse: true,
scrollX: true,
scrollY: '60vh',
paging: false,
"data": tableData.data,
"columns": tableData.columns,
fixedColumns: {
leftColumns: 4
},
"initComplete": function(settings){
//TOOLTIP cell
$(tableName+ ' tbody td').each( function (k, cellObj){
this.setAttribute( 'title', cellObj.innerText );
this.setAttribute( 'data-toggle', "tooltip" );
});
$('[data-toggle="tooltip"]').tooltip({
container: 'body'
});
//add timeout because otherwise user could see a too fast waiting modal
setTimeout(function(){
waitingModal.hidePleaseWait();
}, 1000);
}
});
}
else {
iuprTable.ajax.url("table/"+document.getElementById("hiddenIdCar").value).load();
}
});
});
function notifyMessage(textMessage, typeMessage){
$.bootstrapGrowl(textMessage, {
type: typeMessage, // (null, 'info', 'error', 'success')
});
}
要剪切单元格文本并应用工具提示,我使用了这个css:
<style>
#rdiTable td {
white-space: nowrap;
text-overflow:ellipsis;
overflow: hidden;
max-width:1px;
}
/*Change the size here*/
.tooltip-inner {
max-width: 550px;
}
.tooltip
{
word-wrap: break-word;
}
</style>
我不知道为什么但是有些列会剪切文本,而其他列则超过1000像素,如下图所示:
我尝试使用HTML和CSS尝试使用“columnDefs”的whit max-width,但我总是遇到这个问题。
你知道可能是什么问题吗?感谢