[英]Highlight cell content in DataTable
I'd like to highlight the cell content on focus/click on it. 我想突出显示焦点上的单元格内容/单击它。 For example I would something like
例如我会喜欢
<input onclick="this.select()"/>
on my DataTable. 在我的数据表上。 How can I do that?
我怎样才能做到这一点?
From the documentation... 从文档中...
JS Code: JS代码:
$(document).ready(function() {
$('#example').DataTable( {
select: {
style: 'os',
items: 'cell'
}
} );
} );
Load the following JQ libraries: 加载以下JQ库:
https://code.jquery.com/jquery-1.12.4.js
https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js
https://cdn.datatables.net/select/1.2.5/js/dataTables.select.min.js
Load the following libraries for CSS: 加载以下CSS库:
https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css
https://cdn.datatables.net/select/1.2.5/css/select.dataTables.min.css
$('#table tbody').on('click', 'td', function(){
this.firstElementChild.select();
});
That's my solution and it's working very well! 那是我的解决方案,并且效果很好!
Use CSS for that 为此使用CSS
td{ user-select:all; }
<table> <tr> <th>Firstname</th> <th>Lastname</th> <th>Age</th> </tr> <tr> <td>Jill</td> <td>Smith</td> <td>50</td> </tr> <tr> <td>Eve</td> <td>Jackson</td> <td>94</td> </tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.