1

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>
Reporter
  • 3,897
  • 5
  • 33
  • 47
Rafa
  • 23
  • 1
  • 3
  • What have you tried already? We don't do your coding for you. That's what not SO's for. – Andy Sep 12 '14 at 11:40
  • Can you add the rendered html output of your table? I've got a theory what you looked for. Use the edit button underneath this question. – Reporter Sep 12 '14 at 13:09
  • @reporter
    Cantidad Producto Precio Eliminar
    Total 19.5
    – Rafa Sep 15 '14 at 06:39
  • What exactly do you want to do? Is your goal this, that you want click on a link and whit you delete all rows? – Reporter Sep 15 '14 at 13:32
  • @reporter Yes, the answer below has worked perfectly for me. Thanks a lot!!! – Rafa Sep 17 '14 at 09:10

2 Answers2

3

You can delete by removeRows() function:

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

DEMO

asdf_enel_hak
  • 7,474
  • 5
  • 42
  • 84
0

Try this one

footable.rows.load([])
Saud Khan
  • 786
  • 9
  • 24
matbat
  • 16
  • 3