Checkbox are not submitting after dynamically adding new rows in Datatable
Checkbox are not submitting after dynamically adding new rows in Datatable
Rushdi
Posts: 13Questions: 3Answers: 0
I am using the following code to add a new row in the Datatable. row will be added successfully; however newly added checkbox is not working unless page has been refreshed.
// this method supposed to give alert; however it won't work unless html page has been refreshed
$dataTable.$('input[name=chkbox]').click(function () {
alert(Testing);
});
$dataTable.row.add([
'<input type="checkbox" name="chkbox" value= '+Forum_Id+' />',
'<div class="forumLogo" style="background-image: url(' + response.message.imageUrl + ')"></div>'
+ '<div class="forumData">'
+ '<div class="forumTitle">' + ' <a id="forumTitle" href=' + ForumRoute + '>' + response.message.title + '</a>' + '</div>'
+ HasRecentPost
+ '</div>',
'<div class="forumPostCount">' + response.message.numberOfPosts + ' Posts</div>' +
'<div class="forumUserCount">' + response.message.numberOfUsers + ' Users</div>',
'<div class="forumDescription">'+ response.message.description +'</div>', EditOrDeleteBtn
]).node().id = RowId;
This discussion has been closed.
Answers
You may need to use Delegated Events as discussed in this FAQ.
Kevin
May you please show an example code for my case, because i didn't get it clearly
Please build an example of what you have then we can help fix it. You can start with this:
http://live.datatables.net/
Kevin
Here is the link for a simple example http://live.datatables.net/goniguji/11/edit
Please click on the button (Run with JS), then Click on the Button (Add new Row).
The issue is that newly added rows with checkbox will not print out "Testing" in console once a checkbox has been checked.
Something like this:
http://live.datatables.net/goniguji/12/edit
Kevin
Thanks Kevin. That worked fine