multiple row add
multiple row add
So.. i setup an editor overlay tied to a button "Import" and it pushes only a single field named "csvimport", there i input some comma separated string that matches the columns in the datatable.
I'm then catching this data after submit with preCreate event server-side.. and now I'm wondering what would be the best way to split this down and run multi-insert, triggering each columns validator/formatter etc..
I found a solution client-side on the forums here but I'd much rather do this server-side if possible.
->on( 'preCreate', function ( $e, $row) {
$row['csvinput'] <-- this has a string containing multiple lines of CSV
any ideas?
This question has an accepted answers - jump to answer
Answers
So I added a custom event for backend just as _process is run, to handle the CSV and re-format $data['data']. And then a custom function in the editor class, to handle input of the data and push that back into $data['data'].
Any idea on how to solve this less hacky? This is of course not what I want as a permanent solution but it works like a charm.
I would suggest doing this on the client-side in fact. The
create()
method can be used to create multiple rows with a single Ajax call, and the multi-row editing API can be used to set the values for the fields / rows. Might make an interesting blog post this in fact .Allan
Yeah i tried that on the client side, but had issues with the textarea box not pushing more than a few lines.. and after that output was empty and just felt the code was messy client side.
I cleaned up my Editor.php patch, and marked the code properly so when I upgrade it'll be easy to re-patch.. I'm keeping this 'hack' as is.. but I'm really open to that blog post! ;-)
I wanna be able to push 256 entries minimum with ~50 chars per line of comma separated entries. this works very well server-side.