Generate a list containing the values that appear in the first column of a filtered dataTable

Generate a list containing the values that appear in the first column of a filtered dataTable

lc180lc180 Posts: 7Questions: 3Answers: 0

Pretty much what the title says. I have a button on screen, when I click it I call a function, inside the function I create an arraylist and I want to populate it by pulling the numeric values that are found in the first column of my filtered table.

I played around with table.column( 1 ).data() & table.row( 1 ).data() functionality but with no luck, I'm sure this is not difficult but I'm completely stumped on this. Any suggestions?

FYI - I'm using 1.10.2

Answers

  • lc180lc180 Posts: 7Questions: 3Answers: 0
    edited August 2014

    OK so I was able to make some progress with this.
    I started by just getting the list of all values in the columns.

                 var oTable = $("#example").dataTable();
    
                 var rows = $("#example").dataTable().fnGetNodes();
    
                 var itemIds=[];
    
                  for(var i=0;i<rows .length;i++){ 
                      itemIds.push($(rows [i]).find("td:eq(2)").text());
                  }
    

    This works fine but I want to generate a list of filtered data. I modified the code to use the oTable._ ('tr', {"filter":"applied"}); funtionality and it works! to an extend of what I want:

                 var oTable = $("#example").dataTable();
                 var data = oTable._('tr', {"filter":"applied"});
                 var itemIds=[];
                  for(var i=0;i<data.length;i++){ 
                      itemIds.push($(data[i]).find("td:eq(2)").text());
                  }
    

    When I print the content of 'itemIds' I can see it has 4 entries instead of 6 so the filtering seems to work but the output values are blank. So it looks like my syntax is incorrect for pushing the value to the itemIds array. I've tried a few different ways to find the value but no luck.

    Any suggestions on modifying the below syntax?

    itemIds.push($(data[i]).find("td:eq(2)").text());

  • hhmhhm Posts: 24Questions: 3Answers: 2
This discussion has been closed.