Datatable + Editable Add Row
Datatable + Editable Add Row
Hi,
I am using Add Row example from the Editable plugin site and was trying to figure out the best way to do the following:
I have a database table with: id, first name, last name, last updated on, last updated by
Using the "formAddNewRow" method, I want the user to provide only the first name and last name, and then have the server return back the remaining fields to the DataTables/Editable and then display the entire row.
Using the "formAddNewRow" method, requires me to ask the user for all 5 fields (which I don't want), and then there is no way of getting the correct values. Can someone give me some advice.
Thanks
-Ven
I am using Add Row example from the Editable plugin site and was trying to figure out the best way to do the following:
I have a database table with: id, first name, last name, last updated on, last updated by
Using the "formAddNewRow" method, I want the user to provide only the first name and last name, and then have the server return back the remaining fields to the DataTables/Editable and then display the entire row.
Using the "formAddNewRow" method, requires me to ask the user for all 5 fields (which I don't want), and then there is no way of getting the correct values. Can someone give me some advice.
Thanks
-Ven
This discussion has been closed.
Replies
Looking at the code for the editable plug-in for DataTables you are absolutely correct that it basically expects the data to be in the form. It looks like there is an initialisation option called fnOnNewRowPosted that might be of some use when you combine it with hidden form fields.
1. So what I think needs to be done so you modify your HTML form to have 1 HTML input element for each column in the table (as the code that reads that information looks fairly "haardcoded"!).
2. Then define a fnOnNewRowPosted function. It takes a single argument, the string that is returned from the server (the editable plug-in uses a dataType of 'string', you you'll need to use $.parseJSON to convert the string to a JSON object so you can manipulate it.
3. Finally in your fnOnNewRowPosted function populate the 'values' of the hidden input elements with the information that comes from the server ( $('myInput').val( json.myVal ); for example).
Then the editable plug-in will scan over all the input elements and collect the data from them and add it to the table.
Regards,
Allan