Loop through DataTables table to get all cells content

后端 未结 4 1543
北恋
北恋 2021-02-04 01:21

I am using jquery dataTables to generate the paginated table on my site. I need to run a process that grabs all of the data out of a particular column. Something like :

<
4条回答
  •  灰色年华
    2021-02-04 02:08

    Here's a method using fnGetData()

    First get the data from plugin which will be all rows visible or not. Loop over each row data array, and push index=1( second cell) into new array

         oTable = $('#example').dataTable();
    
          var secondCellArray=[];
          $.each( oTable.fnGetData(), function(i, row){
              secondCellArray.push( row[1]);
        })
    
         console.log( secondCellArray)
    

    EDit : working demo...look in console after render

    http://live.datatables.net/apixiv/edit#javascript,html

提交回复
热议问题