paste into datatable
paste into datatable

I have an excel document that has a lot going on in it, so I can't figure out a way to use the csv importer without the user having to do a lot of manipulation. To make it easier on the end user, if I had a datatable/editor set up with the correct columns, is it possible to have them copy/paste the needed rows/cells into a datatable/editor?
This discussion has been closed.
Replies
They'd be able to cut&paste the cells individually, either with inline/bubble or on the form, but not a row all at once though.
Colin
I would look for a Javascript library to allow for pasting data into an input on the page. Then you can take that input and use
rows().add()
to add to the Datatable. If you need to update a DB you can use an ajax request or usecreate()
to insert the rows.Kevin
awesome. thanks for the tip. I found this code that may work as far as getting it into a table.
https://stackoverflow.com/questions/2006468/copy-paste-from-excel-to-a-web-page
then I will just need to figure out the create() you mentioned.
I can't find any documentation on how to get a datatable saved using the editor.
here is what i have so far. this will take the excel copy/paste and put it into a dataTable:
If you don't need to sue Editor for other functions you can use jQuery ajax() to send the data to your server for saving.
If using Editor the use the
create()
like I mentioned above to create new rows and the DB.Kevin
Yes - if you are using Editor, don’t add it to the DataTable directly yourself. Let Editor do that, and as Kevin says (spot on as always!) use
create()
to instruct Editor to create a new row.Allan
I have it working by instead of reading the excel data into a table, bringing it into an array. then I loop through each row doing an ajax call, row by row. But, I would love to learn how to use the Editor to do this. i am not able to find examples of how to add an entire recordset using .create.
Here is how I am currently doing it:
The
create()
docs show a couple examples. You will do a combination of the 3rd and 4th examples. Take a look at thefield().multiSet()
andsubmit()
docs. I built this simple example that adds two rows on a button click:http://live.datatables.net/zeliruja/1/edit
Kevin
Ok. I seem to have gotten the code working, however, with 118 rows, it is getting an error 'Out of Memory'.
In Javascript or your server script?
Maybe you need to do fewer rows at a time.
The other option is to not use
create()
and instead use what you had before and send the data to the server using a jQuery ajax() request.Kevin
yeah, looks like I will stick with the ajax call. But I will definitely refer to this in the future.