Dynamic column header title
Dynamic column header title
triple_6
Posts: 5Questions: 2Answers: 0
Hi,
Im trying to get column names also from json.
My table :
<table id="example000" class="table table-condensed table-bordered table-hover" cellspacing="0" width="100%">
<thead>
<tr>
<th></th>
<th>Konto</th>
<th>Nazwa</th>
<th>Grupa</th>
<th>Okres 1</th>
<th>Okres 2</th>
</tr>
</thead>
</table>
JS:
var dt = $('#example000').DataTable( {
"language": {
url: 'assets/global/plugins/DataTables-1.10.12/DataTables/Polish.json',
buttons: {
copyTitle: 'Kopiowanie danych',
copySuccess: {
_: 'Skopiowano %d wierszy',
1: 'Skopiowano 1 wiersz'
}
}
},
"processing": true,
"ajax": {
"url": "assets/db/sales_reports_data_compare_v2.php",
"type": "POST",
"data": function ( d ) {
d.from_date1 = $('#from_date1').val();
d.from_date2 = $('#from_date2').val();
d.to_date1 = $('#to_date1').val();
d.to_date2 = $('#to_date2').val();
d.sales = $('#sales').val();
d.klient = $('#klient').val();
d.string = $('#string').val();
}
},
"order": [
[1, 'asc']
],
"lengthMenu": [
[5, 10, 15, 20, -1],
[5, 10, 15, 20, "Wszystko"] // change per page values here
],
"pageLength": 10,
"columns": [
{
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": '<i class="fa fa-plus-square-o"></i>'
},
{ "data": "konto" },
{ "data": "nazwa" },
{ "data": "grupa" },
{ "data": "okres1", "defaultContent": "0.00" },
{ "data": "okres2", "defaultContent": "0.00" }
]
} );
My json data:
{
"draw":0,
"recordsTotal":2,
"recordsFiltered":2,
"data":[
{
"konto":"4065",
"nazwa":"P.P. ARDMET s.c. Jerzy Sobczyk i Przemys\u0142aw Sobczyk",
"grupa":"DT",
"okres1":"450.00",
"okres2":"450.00"
},
{
"konto":"4066",
"nazwa":"MDK Piotr Kraso\u0144",
"grupa":"DT",
"okres1":"250.00",
"okres2":"250.00"
}
],
"columns":[
{
"konto":"Customer account",
"nazwa":"Full name",
"grupa":"Sales group",
"okres1":"2016-01-01 to 2016-01-31",
"okres2":"2016-02-01 to 2016-02-29"
}
]
}
I search whole this forum, API examles and stackoverflow but i can't find any working example how get columns name from "columns" json. Could someone help me with this?
Many thanks!
This discussion has been closed.