Server Side Processing from CSV

Server Side Processing from CSV

HarryHoggHarryHogg Posts: 3Questions: 0Answers: 0
edited January 2013 in General
Hi,

This is a great plugin and I've managed to get this working brilliantly using a JOSN formatted data source, but what would be ace is to get this working from a CSV file, I've done a fair bit of search and the only luck I've had is with this post (http://datatables.net/forums/discussion/comment/12756#Comment_12756) that was brought up a couple of years ago.

But I can't figure out how he is implementing this and how he is then calling the CSV file. I would very much appreciate any help or guidance someone can give me in getting this to work.

Many Thanks

Harry

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    With server-side processing, all the processing is done at the server :-). So it would be up to the server to read the file, process it, filter rows, sort them etc. You'd need to fully implement the protocol described here: http://datatables.net/usage/server-side . How exactly you do that will be highly dependent on your server-side environment.

    Allan
  • HarryHoggHarryHogg Posts: 3Questions: 0Answers: 0
    edited January 2013
    Hi Allan, once again thanks for such a great plugin. I think I might have been wrong with trying to look at this from a server-side processing view and even with an ajax source. But have managed to get it working with dataTable reading directly from the DOM and have the table created before hand. This might not be the best solution but for me was the easiest to set up. I'll add what I found below just incase someone else come across the same problem.

    I first added a CSV file to the DOM in a table using the csv2table plugin.

    [code]$("#ID").csv2table('CSVSource.csv');[/code]

    However to get this to work I had to modify the original plugin to add in a section and to remove all unnecessary styling.

    Next set dataTables to read directly from the DOM table.

    [code]
    setTimeout(function() {
    $('#ID table').dataTable( {
    "fnDrawCallback": function(){$('#ID').animate({opacity:1})}
    });
    },200);
    [/code]

    Adding a setTimeout is needed as it allows the csv2table to finish, I think csv2table does have an on complete callback but I haven't looked into it yet.

    Thanks

    Harry
  • HarryHoggHarryHogg Posts: 3Questions: 0Answers: 0
    edited January 2013
    EDIT-------
    There is an onload function in csv2table so the setTimeout is no longer needed.

    [code]
    $("#ID").csv2table('CSVSource.csv',{
    onload : function(){Initialise dataTable here}
    });
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Sounds like a good solution :-)

    Allan
This discussion has been closed.