Server-side Pulling from CSV Instead

Server-side Pulling from CSV Instead

bridrodbridrod Posts: 14Questions: 2Answers: 0

Hi,
Right now I have server-side setup pulling from MySQL DB with ssp.class.php. I have some limitations on using DB, so I would like to do the same, but using a CSV file instead. Any example on how to do this (if possible?)

Thanks,

Answers

  • kthorngrenkthorngren Posts: 21,205Questions: 26Answers: 4,928

    Datatables doesn't have a built in way to fetch CSV files. You will need to provide the data in a format that Datatables supports, ie, an array of rows where the rows are either objects or arrays. See the data docs for more details.

    Also the doc describes the supported methods to provide data to Datatables. You can use ajax and return a JSON string that contains the CSV file. Or you can use jQuery ajax or some other method to get the CSV file. Then using a Javascript variable you can add the rows at initialization using data or use rows.add().

    TLDR; you will need a server function that can return the CSV file in a format that Datatables supports.

    Kevin

  • bridrodbridrod Posts: 14Questions: 2Answers: 0

    Oh man. Trying to get my head around this... Would it be possible to provide an example of test case "as close as" possible to it?

  • kthorngrenkthorngren Posts: 21,205Questions: 26Answers: 4,928

    I'm assuming you want to read the CSV file and populate the Datatable automatically when its initialized - like your server side processing solution. Sorry I know of no examples like this and its difficult to provide one since this is mostly a server solution.

    Is the CSV file located on a server? If so you will need to use Ajax to send to a URL at the server which will open, read and return the CSV contents. If using PHP maybe this tutorial will get you started. I don't use PHP so don't know what changes are needed or what the data format looks like.

    If you want the user to upload a selected CSV file you can use Editor for that. See this example.

    Kevin

  • kthorngrenkthorngren Posts: 21,205Questions: 26Answers: 4,928

    Here is a thread that might help too. Looks like the OP is using Papa Parse to fetch and load the CSV file form the server. See the last code snippet. Maybe you can do something similar.

    Kevin

Sign In or Register to comment.