Initialization of datatable columns dynamically
Initialization of datatable columns dynamically
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
Hi, already have the problem solved?