Get all data from table with cell dropdown filter

Get all data from table with cell dropdown filter

jmleitaojmleitao Posts: 6Questions: 2Answers: 0

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

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    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

  • jmleitaojmleitao Posts: 6Questions: 2Answers: 0

    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.

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,769
    Answer ✓

    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 the body: function( data, row, col, node ) starts counting the col parameter at 0. So in your case the table column 1 is col 0 in the body function.

    Next I used .cell( {row: row, column: col+1} ) to offset the zero based col with the real column number.

    The reason for the [object Object] is that your return outros; is returning the whole row of data for each cell that is not one of the select cells. Changed it to simply return data;.

    Kevin

  • jmleitaojmleitao Posts: 6Questions: 2Answers: 0

    Hi @kthorngren

    Thank you very much, you made my day.

This discussion has been closed.