I would keep the logic on server and do all the csv rendering eventdriven.
Here you have a good csv lib: https://github.com/goodby/csv
So the process would be something like this:
- Client: Load csv preformated (via php) from server and display in html
- Client: Do MVVM bindings etc.
- Client: If an event is called (like add, update etc.) send
eventrequest to server
- Server: Recieve event -> Process (with transactions if needed) -> reformat csv, save it
and send back to client
- Client: Retrieve and apply MvvM bindings
Otherwise you need redundant csv logic in client and server whats not a fine approach.
Do you know what I mean or should I do you an example?
The csv library supports complex csv binding and easy appending like:
$csv = new parseCSV();
$csv->parse('yourcsv.csv');
$csv->data[1] = array('updatekey' => 'new Value');
$csv->save();
Client side example:
//retrieve your csv (view rendered or async with ajax
var csv;
var mutableDataArray = $.csv.toArray(csv);
//do manipulation here
//for example
mutableDataArray[0].name = 'A new name to first record';
//serialize back
var newCsv = "";
for(var i in mutableDataArray) {
var data = mutableDataArray[i].join(",");
newCsv += i < mutableDataArray[i].length ? data + "
" : data;
}
//do something with newCsv