Search code examples
javascriptjqueryfootable

How to delete all rows in a footable?


I have a footable that I need to clean. I mean, I need to delete all rows in the footable. Is there any footable function to do that? Or do I need to delete rows one by one?

I tried to reinitialize the table doing this:

$('.footable').footable();

I also have tried to iterate between the rows like this:

var footable = $('table').data('footable');

//This is the problem I don´t know how to get first row in the table.
var row = ??????.parents('tr:first'); 

var next=row.next();
for (var i=0; i<long-1; i++){
  footable.removeRow(next);
  next=row.next();
}
footable.removeRow(row);

And my corresponding html source code:

<table class="footable footable-loaded">
<thead>
<tr>
    <th>Cantidad</th>
    <th>Producto</th>
    <th>Precio</th>
    <th>Eliminar</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
    <tr>
        <th></th>
        <th>Total</th>
        <th id="total">19.5</th>
        <th></th>
    </tr>
</tfoot>
</table>

Solution

  • You can delete by removeRows() function:

    function removeRows(){
        $(".footable>tbody>tr").each(function(index, elem){
            $(elem).remove();
         });
    }
    

    DEMO