使用javascript从DataTable插件中检索数据

时间:2016-08-10 17:14:04

标签: javascript jquery

我使用DataTable插件使用javascript从数据库生成数据。我在表标签中显示数据,如

foreach ($data as $row) {
                                        $total += $row->price;
                                        ?>
                                        <tr>
                                            <td><?php echo $row->id; ?></td>
                                            <td><?php echo $row->created_date; ?></td>
                                            <td><?php echo $row->vender; ?></td>
                                            <td><?php echo $row->usertype; ?></td>
                                            <td><?php echo $row->price; ?></td>
                                            <td><?php echo $row->payment_type; ?></td>
                                            <td><?php echo $row->vender_inv; ?></td>
                                            <td><?php echo $row->note; ?></td>
                                            <td><a class="example-image-link" href="<?php echo $row->image; ?>" data-lightbox="example-1"><img style="width:100px !important; height:100px !important;" class="example-image" src="<?php echo $row->image; ?>" alt="image-1" /></a>
                                            </td>
                                        </tr>

                                        <?php
                                    }

现在我想从中检索单个行,我试图像这样做

var table = $('#myTable').DataTable();
        table.column(4).eq(0).each( function ( colIdx ) {
            console.log( colIdx, table.column( colIdx ).search() );
        } );

1 个答案:

答案 0 :(得分:0)

查看rows()API:https://datatables.net/reference/api/rows().every()

table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
    var data = this.data();
    // ... do something with data(), or this.node(), etc
} );