Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
82
rated 0 times [  85] [ 3]  / answers: 1 / hits: 32846  / 9 Years ago, sat, april 4, 2015, 12:00:00

I would like to change the title of a column my datatable generated by jQuery Datatable plugin



Do you know if I can do something like this:



 table = $('#example').DataTable({
data: source_dataTable,
columnDefs: defs,

dom: 't<topf>rt<bottomlpi><clear>',
});
// WHAT I WANT TO DO:
table.column(0).title.text(new title for the column 0)


?



It renders a html a first line like that:



 <table id=example class=row-border hover dataTable no-footer role=grid aria-describedby=example_info style=width: 1140px;>
<thead>
<tr role=row>
<th class=sorting tabindex=0 aria-controls=example rowspan=1 colspan=1 aria-label=S&amp;#233;lectionn&amp;#233;: activer pour trier la colonne par ordre croissant style=width: 94px;>Sélectionné</th>

<th class=sorting tabindex=0 aria-controls=example rowspan=1 colspan=1 aria-label=Anglais : activer pour

trier la colonne par ordre croissant style=width:

62px;>Anglais </th>

</tr>
</thead>
</table>


...



In a normal table the code bellow work , but for datatable rendered by jQuery plugin, it doesn't:



$('#example tr:eq(0) th:eq(0)').text(Text update by code);


Maybe there is a API method or another dom way?


More From » jquery

 Answers
18

I found a solution that really do it dynamically



$(table.column(1).header()).text('My title');

[#67200] Wednesday, April 1, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
benitoh

Total Points: 150
Total Questions: 113
Total Answers: 104

Location: India
Member since Wed, Aug 26, 2020
4 Years ago
benitoh questions
Sun, Mar 21, 21, 00:00, 3 Years ago
Mon, May 13, 19, 00:00, 5 Years ago
;