Я применил код Devansh J вопроса ( Как показать меньше текста в таблице, используя таблицы данных? ).Я поместил в 3 клона моей таблицы систему, которая позволяет обрезать текст, нажимая на ссылки «читать больше» или «читать меньше».Эта система работает хорошо, за исключением того, что я хотел бы, чтобы текст был обрезан только при необходимости.Итак, для этого мне нужно знать начальную высоту ячейки.Если эта высота больше X, я буду отображать ссылки.Моя проблема в том, что я не могу восстановить высоту клетки.ClentHeight всегда показывает мне 0. Ты можешь мне помочь?
function rendertable(dataSet){
var table = $('#table_RI').DataTable( {
data: dataSet,
searching: true,
paging: false,
order: [[ 0, 'desc' ],[ 9, 'desc' ]],
dom: '<"wrapper"ftip>',
oLanguage: {
"sSearch": "Search<br>release:"
},
autoWidth: false,
columnDefs: [
{"targets": 0 },
{ "title": "Reference IR", "targets": 1 },
{ "title": "Issue", "targets": 2 ,"orderable": false},
{ "title": "Abstract","targets": 3,"orderable": false},
{ "title": "status", "targets": 4 },
{ "title": "1st Transaction", "targets": 5,"orderable": false },
{ "title": "Program", "targets": 6,"orderable": false },
{ "title": "owner", "targets": 7,"orderable": false},
{ "title": "Brand", "targets": 8,"orderable": false },
{ "title": "Create date", "targets": 9 },
{ "title": "Target date", "targets": 10, "orderable": false },
{ "title": "Transactions impacted", "targets": 11,"orderable": false},
{
targets: [2,3,11],
createdCell: function(cell) {
var $cell = $(cell);
console.log($(cell)[0].clientHeight);
if($(cell)[0].clientHeight > 73){
$(cell).contents().wrapAll("<div class='content'></div>");
var $content = $cell.find(".content");
$(cell).append($("<p class='readMoretxt' >Read more</p>"));
$btn = $(cell).find("p");
$content.css({
"height": "30px",
"overflow": "hidden"
});
$cell.data("isLess", true);
$btn.click(function() {
var isLess = $cell.data("isLess");
$content.css("height", isLess ? "auto" : "30px")
$(this).text(isLess ? "Read less" : "Read more")
$cell.data("isLess", !isLess)
})
}
}
}]
});
$('#table_RI_filter input').on( 'keyup', function () {
table
.columns( 0 )
.search( this.value )
.draw();
});
table.columns.adjust().draw();
}