admin管理员组文章数量:1401627
I checked datatables api but couldn't see anything under row() functions. Basically I want to achieve this kind of functionality:
var myTable = $('#example').DataTable();
myTable.row(i).fontSize = dynamicValue;
Or
myTable.row(i).css('font-size', dynamicValue);
I checked datatables api but couldn't see anything under row() functions. Basically I want to achieve this kind of functionality:
var myTable = $('#example').DataTable();
myTable.row(i).fontSize = dynamicValue;
Or
myTable.row(i).css('font-size', dynamicValue);
Share
Improve this question
edited Mar 21, 2016 at 9:24
Gaurav Aggarwal
10.2k8 gold badges41 silver badges76 bronze badges
asked Mar 21, 2016 at 9:09
brainmassagebrainmassage
1,2627 gold badges23 silver badges46 bronze badges
1
-
2
Why not use jQuery directly?
myTable.find('tr').eq(i).addClass('big-font');
– Rory McCrossan Commented Mar 21, 2016 at 9:11
1 Answer
Reset to default 4If you want a persistent solution you have to go through the API. If you have a dataTable instance :
var table = $('#example').DataTable()
and a CSS class :
.larger-font {
font-size: 120%;
}
then you can permanently change the font-size
of a clicked row by :
$('#example').on('click', 'tr', function() {
table.row(this).nodes().to$().addClass('larger-font')
})
row(this)
gives you the internal row instance
nodes()
gives you the entire <tr>
DOM node
to$()
return that DOM node as jQuery instance
addClass()
adds the CSS
demo -> http://jsfiddle/tgefobbq/
If you want to manipulate inline CSS instead of injecting classes you just do this the same way :
table.row(this).nodes().to$().css('font-size', '120%')
to$()
is not necessary, just convenient - you can target the "raw" DOM as well :
table.row(this).nodes()[0].style.cssText = 'font-size:120%;
But either way, it is important you retrieve the DOM nodes through the API, not through jQuery or any other way.
本文标签: javascriptHow can I change the font size of a row dynamically with datatablesStack Overflow
版权声明:本文标题:javascript - How can I change the font size of a row dynamically with datatables? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744284740a2598822.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论