admin管理员组文章数量:1225081
I want to appends ellipsis (…) to the end of row of datatable(in this comment column). For this I have added jQuery ellipsis js. how should I specify height to jQuery data table row so that it only show 2 line. Right now height is adjusted according to length of text.
This is my jQuery table
<div id="comments">
<c:choose>
<c:when test="${null ne comments and not empty comments}">
<table id="dataTable2" cellpadding="0" cellspacing="0" border="0" class="display" style="width:100%;">
<thead><tr><th>Id</th>
<th width="15%">User</th>
<th width="15%">Role</th>
<th width="45%">Comment</th></tr></thead>
<tbody>
<c:forEach items="${comm}" var="comm" varStatus="status">
<tr><td>${commentmentId}</td>
<td width="15%">${comm.userFullName}</td>
<td width="15%">${comm.userRoleName}</td>
<td width="45%" style="height:20px" class="ellipsis multiline">${comm.CommentAbbreviation}</td></tr>
</c:forEach>
</tbody>
</table>
</c:when></c:choose>
</div>
jquery.autoellipsis.js
(function($) {
$.fn.ellipsis = function()
{
return this.each(function()
{
var el = $(this);
if(el.css("overflow") == "hidden")
{
var text = el.html();
var multiline = el.hasClass('multiline');
var t = $(this.cloneNode(true))
.hide()
.css('position', 'absolute')
.css('overflow', 'visible')
.width(multiline ? el.width() : 'auto')
.height(multiline ? 'auto' : el.height());
el.after(t);
function height() { return t.height() > el.height(); };
function width() { return t.width() > el.width(); };
var func = multiline ? height : width;
while (text.length > 0 && func())
{
text = text.substr(0, text.length - 1);
t.html(text + "...");
}
el.html(t.html());
t.remove();
}
});
};
})(jQuery);
css class
.ellipsis {
white-space: nowrap;
overflow: hidden;
}
.ellipsis.multiline {
white-space: normal;
}
How should I set height to datatable row ?
I want to appends ellipsis (…) to the end of row of datatable(in this comment column). For this I have added jQuery ellipsis js. how should I specify height to jQuery data table row so that it only show 2 line. Right now height is adjusted according to length of text.
This is my jQuery table
<div id="comments">
<c:choose>
<c:when test="${null ne comments and not empty comments}">
<table id="dataTable2" cellpadding="0" cellspacing="0" border="0" class="display" style="width:100%;">
<thead><tr><th>Id</th>
<th width="15%">User</th>
<th width="15%">Role</th>
<th width="45%">Comment</th></tr></thead>
<tbody>
<c:forEach items="${comm}" var="comm" varStatus="status">
<tr><td>${comment.commentId}</td>
<td width="15%">${comm.userFullName}</td>
<td width="15%">${comm.userRoleName}</td>
<td width="45%" style="height:20px" class="ellipsis multiline">${comm.CommentAbbreviation}</td></tr>
</c:forEach>
</tbody>
</table>
</c:when></c:choose>
</div>
jquery.autoellipsis.js
(function($) {
$.fn.ellipsis = function()
{
return this.each(function()
{
var el = $(this);
if(el.css("overflow") == "hidden")
{
var text = el.html();
var multiline = el.hasClass('multiline');
var t = $(this.cloneNode(true))
.hide()
.css('position', 'absolute')
.css('overflow', 'visible')
.width(multiline ? el.width() : 'auto')
.height(multiline ? 'auto' : el.height());
el.after(t);
function height() { return t.height() > el.height(); };
function width() { return t.width() > el.width(); };
var func = multiline ? height : width;
while (text.length > 0 && func())
{
text = text.substr(0, text.length - 1);
t.html(text + "...");
}
el.html(t.html());
t.remove();
}
});
};
})(jQuery);
css class
.ellipsis {
white-space: nowrap;
overflow: hidden;
}
.ellipsis.multiline {
white-space: normal;
}
How should I set height to datatable row ?
Share Improve this question edited Feb 13, 2017 at 20:48 marc_s 755k184 gold badges1.4k silver badges1.5k bronze badges asked Jan 20, 2012 at 11:50 RajeRaje 3,33315 gold badges54 silver badges70 bronze badges3 Answers
Reset to default 14This worked great for me
.dataTable th, .dataTable td {
max-width: 200px;
min-width: 70px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
I found a solution. It isn't the most correct way but it works. I wrapped the data within the in a div and I have modified following line.
<td width="45%" style="height:20px" class="ellipsis multiline">${comm.CommentAbbreviation}</td>
Replace by
<td width="45%"><div class="ellipsis multiline" style="height: 35px;">${comm.CommentAbbreviation}</div></td>
It works for me
.td-limit {
max-width: 70px;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
本文标签: javascriptHow to apply jQuery ellipsis to jQuery datatable rowStack Overflow
版权声明:本文标题:javascript - How to apply jQuery ellipsis to jQuery datatable row - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739420733a2162503.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论