[英]HTML jquery collapsable tables
I've been working on this for a bit and I cant quite make this behave the way I want it. 我已经为此工作了一段时间,我无法完全按照我想要的方式进行操作。
Basically What I need is a way to keep all "text" cells the same size on page load and if they have more text then can fit in the cell add an ellipse (...). 基本上,我需要的是一种在页面加载时将所有“文本”单元格保持相同大小的方法,如果它们包含更多文本,则可以在单元格中添加一个椭圆(...)。 Then when you click on the cells that have the ellispe they will expand allowing you to read the entire text rather then the portion showing. 然后,当您单击带有椭圆形的单元格时,它们将展开,使您可以阅读整个文本,而不是显示的部分。
Here is a jsfiddle that I did that shows the problem: http://jsfiddle.net/7ugmx/1/ 这是我执行的jsfiddle来显示问题: http : //jsfiddle.net/7ugmx/1/
<table class="table" style="margin:0;">
<tr>
<th width="10%" style="border-top:0;">Id</th>
<th style="border-top:0;">Text</th>
<th width="10%" style="border-top:0;">Data</th>
</tr>
</table>
<div class="data">
<table class="table table-striped">
<tr>
<td width="10%">12.1.124.144</td>
<td class="slide">testing updatestesting updatestesting updatestesting updatestesting updates /* SNIP */</td>
<td width="10%">2014-02-02 18:01:14</td>
</tr>
<tr>
<td width="10%">12.1.124.144</td>
<td class="slide">testing updates</td>
<td width="10%">2014-02-02 18:01:13</td>
</tr>
<tr>
<td width="10%">12.1.124.144</td>
<td class="slide">testing updates</td>
<td width="10%">2014-02-02 18:01:13</td>
</tr>
<tr>
<td width="10%">12.1.124.144</td>
<td class="slide">testing updates</td>
<td width="10%">2014-02-02 18:01:13</td>
</tr>
<tr>
<td width="10%">12.1.124.144</td>
<td class="slide">testing updates</td>
<td width="10%">2014-02-02 18:01:13</td>
</tr>
/* SNIP */
</table>
</div>
Here is the jquery script I created. 这是我创建的jQuery脚本。
$(".slide").click(function () {
$(this).slideToggle(200);
});
As you can see on jsfiddle, the entire text cell starts out normal sized, and when clicked, vanishes all together. 正如您在jsfiddle上看到的那样,整个文本单元格以正常大小开始,并且在单击时全部消失。
Is it possible to have the cell start minimized showing 1 line of text, and then maximize showing its entirety on click? 是否可以使单元格开始处最小化以显示1行文本,然后最大化显示其整体单击数?
Thanks for any help. 谢谢你的帮助。
Its possible, here is one resolution: 有可能,这里是一种解决方法:
/* CSS */
.slide {
text-overflow: ellipsis;
width: 200px;
white-space: nowrap;
overflow: hidden;
}
/* JS */
$(".slide").click(function () {
$(this).toggleClass('slide');
});
And working example : JSFIDDLE 和工作示例: JSFIDDLE
[EDIT] [编辑]
Here is a example with wrapped cells and fixed div width as described in comment : SECOND EXAMPLE 这是一个带有包裹单元格和固定div宽度的示例,如注释中所述: 第二个示例
I'm throwing this out just as an idea/thought. 我只是出于想法/想法而将其丢弃。 FIDDLE 小提琴
Instead of a slider, I use a jQuery dialog as a popup that opens with the contexts of the td/div that is clicked on. 我使用jQuery对话框而不是滑块,将其弹出,并带有单击的td / div的上下文。 On mouseout, it closes. 在mouseout上,它关闭。
JS JS
var popupdialog = $('#popupdialog').dialog({
autoOpen: false,
width: 'auto',
height: 'auto',
position: {my: 'top right',
at: 'middle left',
of: '.hidden'}
});
$('.table td div').click(function(){
popupdialog.dialog('open');
var cloneme = $(this).clone();
$('#popupdialog').html(cloneme);
});
$('.table td div').mouseout(function(){
$(this).css('background-color', 'transparent');
popupdialog.dialog('close');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.