Get all data from table with cell dropdown filter
Get all data from table with cell dropdown filter
Hello people,
i build a table from a DB with 2 dropdown filter (col 5 and col 7), i can export the correct data chosen from dropdown but i can't get the rest of data from table.
I don't want to export col 0 and when i export without col 0, the data was exported to the wrong column in the file.
This is the code that i use:
exportOptions : {
columns: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],
format: {
body: function( data, row, col, node ) {
// This is what i want
if (col == 5) {
valor5=minha.tabela
.cell( {row: row, column: col} )
.nodes()
.to$()
.find(':selected')
.text();
}
if (col == 7) {
valor7=minha.tabela
.cell( {row: row, column: col} )
.nodes()
.to$()
.find(':selected')
.text();
return valor7;
}
// This does't work to export the rest of the table.
outros=minha.tabela
.rows()
.data()
.to$()
.text();
return outros;
}
}
}
}
],
I want to put the data to the right column and export all data to the file, please help and i'm sorry for my bad english.
This question has an accepted answers - jump to answer
Answers
Hi @jmleitao ,
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi @colin,
Thanks for your sugestion.
This is the test page http://live.datatables.net/xipahiba/1/
I want to correct the exported data when i exclude the first column and the rest of the table values, instead of "[object Object]" (see export file in test page).
TIA.
I put some debug console.log statements in the export so you can see what is happening.
http://live.datatables.net/wosavaju/1/edit
You are exporting
columns: [1,2,3,4,5,6],
but it looks like thebody: function( data, row, col, node )
starts counting thecol
parameter at 0. So in your case the table column 1 iscol
0 in the body function.Next I used
.cell( {row: row, column: col+1} )
to offset the zero basedcol
with the real column number.The reason for the
[object Object]
is that yourreturn outros;
is returning the whole row of data for each cell that is not one of the select cells. Changed it to simplyreturn data;
.Kevin
Hi @kthorngren
Thank you very much, you made my day.