Adding an Input/Row Dynamically to Edit
Adding an Input/Row Dynamically to Edit
kraftomatic
Posts: 78Questions: 13Answers: 0
Hey All,
I have a Datatable with some basic data on each row, along with a button the left of each row. There are two form options - one of which, when selected, requires the user to fill out a reason for their selection.
What I'd like to do is something similar to the below example, where a row is created with an input field, where the user can enter in some text. Nothing more, just data that's saved when the form/table is submitted.
Any idea how I can do this? Here's the example I was thinking of:
http://datatables.net/release-datatables/examples/api/add_row.html
Thanks in advance.
I have a Datatable with some basic data on each row, along with a button the left of each row. There are two form options - one of which, when selected, requires the user to fill out a reason for their selection.
What I'd like to do is something similar to the below example, where a row is created with an input field, where the user can enter in some text. Nothing more, just data that's saved when the form/table is submitted.
Any idea how I can do this? Here's the example I was thinking of:
http://datatables.net/release-datatables/examples/api/add_row.html
Thanks in advance.
This discussion has been closed.
Replies
How are you currently adding the row? It sounds like you need to use fnAddData with the HTML that you want for the cell in question specified in the data being added to the table. It just does an .innerHTML write, so you can pass in whatever HTML you want.
Allan
[code]
function fnClickAddRow() {
$('#example').dataTable().fnAddData( [
giCount+".1",
giCount+".2",
//giCount+".3",
"",
giCount+".4" ] );
giCount++;
}
[/code]
Thanks.
Allan
http://witchkraftracing.com/allan/wk_mockup_test.html
I basically want to click the button, and if "Do not deliver" is selected, then show the input field where the user can give a reason why.
Currently I have the "Add a row" functionality separate and partially working in the example.
Thanks for your help!
@kraftomatic - Really sorry this slipped my mind back in December. I suspect that you don't really want to use fnAddRow in this case, since rows are effectively independent in DataTables - there would be nothing to tie the "reason" row, to the row that it was marked for.
What I would suggest is having a hidden `` in the same cell as the 'Delivery' button and add an event handler which will show or hide that element based on the selection made in the Delivery column. Does that sound reasonable?
Allan