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
Add a ment  | 

1 Answer 1

Reset to default 4

If 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