Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8651035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:57:51+00:00 2026-06-12T13:57:51+00:00

I am using jQuery datatables to display some data. Each row has an edit

  • 0

I am using jQuery datatables to display some data. Each row has an edit button for which I register a click handler with live(), so that it works with pagination. I am doing it by class since I have to do it for every row.
Something like:
Datatables with live click event function

This works fine, but the problem happens when user does a search again and I do an ajax request to fetch a new set of results.

I just replace the existing table in the dom with a new one. Now when I click on row 1 it pops up the edit dialog for row 1. I click on row 2 it pops up the edit dialog for row 1. I click on row 2 again it pops up the edit dialog for row 2 this time.

Then I click on row 3 again and again. It pops up the edit dialog for row 2 thrice before it shows the dialog for row 3.

This keeps on increasing. I don’t understand if I am replacing the entire dataTable in the div with jQuery why should it register multiple events?

In case it matters, I have autoopen set to false in my dialog initializer and I explicitly open and close it.

Edit (More Details):

I am having a difficult time creating an example … but some more detail … I figured out that since I am using live() function to register calls across pagination the click registration mechanism exists. So when I replace the table with the same structure the click function is registered due to the first call to live(). But I make another call to live() by default and now two click events are registered. Then when I replace again three event clicks are registered. I tried overcoming this by registering events with jQuery click() after checking if a click event is already registered. Helps with the multiple events part but does not register events across datatables pages.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:57:52+00:00Added an answer on June 12, 2026 at 1:57 pm

    Fixed the problem

    The issue was I could not just register for click event on elements within the datatable rows. The events would not be registered across datatable pages.

    Using live() to register the events helped and on page change the events would be registered automatically.

    But for my usecase that led to another problem every time I did a search, I would replace the datatable with a new one. The new datatable would register for those events again. So that meant multiple handlers being invoked for the same element. Because the live() function was called twice on the same class and jquery is not expected to compare whether two callback handlers are the same.

    I veered in a different direction and tried to register click events using .click() in place of .live() on page change using the page event (http://datatables.net/docs/DataTables/1.9.beta.1/#page_details). This did not help since the events the page change event was invoked before the contents were refreshed with the events on the new page.

    I also tried using click() instead of live() and binding click only if it had not already been registered using the example given here https://stackoverflow.com/a/6361507/161628.
    This technique worked across table replace but not across multiple pages.

    Ultimately I found the .die() function. I invoke it before I call the live() function. The call to live() ensures that event handlers are registered on page change while the call to die() ensures I unregister live() events made previously on elements of that class. I avoid multiple calls to live() function this way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using DataTables (jQuery plugin) to display my tabular data. If fetches data
I'm trying to select a nested table to display some tabular data using jQuery
I am using DataTables to display row data, in the last column on the
I'm using jquery datatables to display data inside grid. On init page load script
I am using jquery.dataTables (1.8.1) to display a list of data, and I am
I'm using the jQuery DataTables plugin to display data being returned from an AJAX
I am using jquery datatables to display data from a mysql database. When you
I am using jquery plugin datatables and the css demo_table.css that has been using
Hello i am using Jquery data table to display a table from the server
I'm using jquery datatables, and a jqueryui range slider. Datatables has a range filter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.