multiple datatables with different datasources
multiple datatables with different datasources
simondatas
Posts: 4Questions: 3Answers: 0
Hello,
I have multiple datatables like that and I would like to initialise them all with the same design but different datasources :
table = $('#allTweetsTable').DataTable({
select: true,
order: [[ 5, "desc" ]],
"ajax": {
"type": "GET",
"url": myPath+"/refresh",
"dataSrc": function(data){
//console.log(data);
newDatas=data;
//console.log(newDatas);
return newDatas;
},
},
columns:[
{data : "lang",width: '40px'},
{data : "source",width: '70px'},
{data : "author.screen_name",width: '70px'},
{data : "author.description",width: '250px'},
{data : "full_text",width: '300px'},
{data : "created_at"},
{data : "author.location"},
{data : "author.followers_count"},
{data : "author.verified"},
{data : "author.name"}
],
scrollY: "700px",
scrollX: true,
scrollCollapse: true,
fixedColumns: true
});
table1 = $('#officialsTable').DataTable({
order: [[ 5, "desc" ]],
"ajax": {
"type": "GET",
"url": myPath+"/refreshOfficials",
"dataSrc": function(data){
//console.log(data);
newDatas=data;
//console.log(newDatas);
return newDatas;
},
},
columns:[
{data : "lang"},
{data : "source"},
{data : "author.screen_name"},
{data : "author.description"},
{data : "full_text"},
{data : "created_at"},
{data : "author.location"},
{data : "author.followers_count"},
{data : "author.verified"},
{data : "author.name"}
]
});
Is there a way I can do that without repeating all this code ?
Thanks a lot !!
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
Here is an example:
https://datatables.net/examples/basic_init/multiple_tables.html
Kevin
See also this section of the manual for how to set defaults.
Allan