0

Context:

I am using the dataTables jquery library with my asp.net mvc model view. I have an item model containing a list of department models in it. I have a Html.EditorFor() to display the list of department models in the dataTables table.

Problem

Each row has a checkbox that has a click function that will delete the row through an ajax post request. It works great on the first page of datas. But on the other pages, the click emitter isnt set up and thus the ajax request doesn't fire. It only works for the first page of rows on the dataTables UI.

What can I do to fix this?

3
  • a jsfiddle would be great for this Commented Sep 12, 2013 at 16:52
  • Could you show us how you add this "click" listener to your checkboxes? :) Commented Sep 12, 2013 at 17:12
  • Found a solution, redundant but works. I added a click handler to the <a> tags (Next, Prev) which will add in the click handler for the checkboxes again. Commented Sep 12, 2013 at 17:36

1 Answer 1

1

You have to attach click event handler with jquery on. Because after paging dataTables reload the tableBody and all attached event handler, which are not attached for live mode, will be lost. Something like this..

$("#dataTableWrapper").on("click", "td", function(event){ 
   // your code 
});
Sign up to request clarification or add additional context in comments.

2 Comments

This should work indeed. That why I asked him to show us how he attaches the listener to the click event as he may already have the "on" event listener...
thanks yeah that worked. i wanted to add the code into this issue but it wouldnt let me edit what i wrote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.