Search code examples
javascriptjqueryexport-to-csvfootable

FooTable.Export: Export to CSV on filtered rows


I'm using FooTables and trying to implement the export table functionality. I've looked at the little bit of documentation they have and I think I'm implementing it correctly, however even when I apply a filter on the table the export still returns all rows. I'm wondering if I'm missing something or not quite implementing it correctly.

$('#exportFooTable').on('click', function () {
    var table = FooTable.get('#customerItems');
    var csv = new FooTable.Export(table).csv(true);
    // do stuff;
});

Initially I thought it was due to pagination but the export was returning all rows. I'm at a loss and was thinking of just implementing my own export at this point, but I figured I would see if anyone has any insight before I go down that road.

Update: I doing some further reading I guess I should be calling this as such:

$('#exportFooTable').on('click', function (e) {
    var csv = FooTable.get('#customerItems').toCSV(true);
    // do stuff;
});

However this gives me a type error stating that toCSV is not a function. Does anyone know why this error is being thrown and how to resolve it?


Solution

  • The following code does work. I thought I had the latest version of FooTable standalone since I used the download link from their website found here: https://fooplugins.github.io/FooTable/docs/getting-started.html#download

    $('#exportFooTable').on('click', function (e) {
        var csv = FooTable.get('#customerItems').toCSV(true);
        // do stuff;
    });
    

    However this is version 3.1.5 in which there is a bug that causes the export to not work. If you want to be sure you have the latest version (3.1.6) you should go to the following link, find the appropriate version (Bootstrap, Standalone or Individual Components) and download the 3.1.6 zip file for that version: https://github.com/fooplugins/FooTable/tree/V3/releases