Initialization of datatable columns dynamically

Initialization of datatable columns dynamically

mehtabmehtab Posts: 1Questions: 1Answers: 0
edited May 2014 in DataTables 1.10

I am trying to initialize datatable columns dynamically by using variable, it is not working.

datainit = "{ 'data': 'note_ID_Benef' },{ 'data': 'InjVul' },{ 'data': 'Area' },{ 'data': 'Approach' },{ 'data': 'FirstAssDate' },{ 'data': 'note_Team_Info' },{ 'data': 'Team_Number' },{ 'data': 'Team_Name' },{ 'data': 'data': 'Need' }";

jQuery('#example').dataTable( {

"ajax": "js/obj.txt",

"columns": [datainit]

});

When I add the above variable text hardcoded instead of "datainit",

jQuery('#example').dataTable( {

"ajax": "js/obj.txt",

"columns": [{ 'data': 'note_ID_Benef' },{ 'data': 'InjVul' },{ 'data': 'Area' },{ 'data': 'Approach' },{ 'data': 'FirstAssDate' },{ 'data': 'note_Team_Info' },{ 'data': 'Team_Number' },{ 'data': 'Team_Name' },{ 'data': 'data': 'Need' }]

});

The datatable works.

Anyone knows how to fix this problem?

Please help me out. Thanks in advance!

Answers

This discussion has been closed.