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 8691821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:12:09+00:00 2026-06-13T00:12:09+00:00

I have the following HTML: <table> <thead> <tr> <th>Id</th> <th>Name</th> <th>Description</th> <th>Actions</th> </tr> </thead>

  • 0

I have the following HTML:

<table>
    <thead>
        <tr>
            <th>Id</th>
            <th>Name</th>
            <th>Description</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Item 1</td>
            <td>Description of Item 1</td>
            <td>
                <a href="#" data-action="edit" data-item-id="1">Edit</a>
                <a href="#" data-action="delete" data-item-id="1">Delete</a>
            </td>
        </tr>
        <tr>
            <td>2</td>
            <td>Item 2</td>
            <td>Description of Item 2</td>
            <td>
                <a href="#" data-action="edit" data-item-id="2">Edit</a>
                <a href="#" data-action="delete" data-item-id="2">Delete</a>
            </td>
        </tr>
    </tbody>
</table>

The table rows (tr elements) are added dynamically.

I wire up a click event to all Edit links like this:

void wireUpTableEvents() {
  var editLinks = queryAll('#order-items table tbody [data-action="edit"]');

  editLinks.forEach((element) {
    element.on.click.add((event){
      print(element.attributes['data-item-id']);
    });
  });
}

As said above, the table rows (tr elements) are added dynamically so the above code only works if I call wireUpEvents after I execute the method which adds the rows.

Does anyone know the syntax or adding a event listener to elements using DART‘s on.click.add() when the elements are dynamcially added in the future?

I tried checking the DART documentation but the documentation on Event Listeners is blank.

If I would be using jQuery I could be using something similar to:

$("#order-items table")on("click", "tbody [data-action="edit"]", function(){...})

…but I want to write my sample app only using DART.

Edit
Though future sounds great for callbacks it seemed slightly overkill for what I needed as there is no long running task in my scenario.

The closest I was able to get to attach my event listener to a static element but processing the click events of future sub-elements was this:

void wireUpTableEvents() {
    var tableBody = query('#order-items table tbody');

    // Attach Event Listener to the static tbody, which always exists.
    tableBody.on.click.add((event) {
        var clickedElement = event.srcElement;
        var itemId = clickedElement.attributes['data-item-id'];

        // Check if the clicked element was either one of the edit links or one of the delete links.
        switch (clickedElement.attributes['data-action']) {
        case 'edit':
            // Replace print with calling a method to process edit request for this item.
            print('processing edit click from item with id: $itemId');
            break;
        case 'delete':
            // Replace print with calling a method to process delete request for this item.
            print('processing delete click from item with id: $itemId');
            break;
        }
    });
}​

The above code can execute before any of the actual tr elements are loaded and still works after the tr elements are loaded at some unknown later stage.

I also found that it now covers any dynamically added row, pre-loaded ones as well as other dynamically added ones for new records etc.

  • 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-13T00:12:11+00:00Added an answer on June 13, 2026 at 12:12 am

    It sounds like you need to use Dart’s Future object. John Evans has a recent post that gives an excellent overview. I’ll try to give a simple example:

    Let’s say I have a class called htmlInDart which I call as follows:

    void main() {
      var htmlExample = new HtmlInDart().createStyles();
      htmlExample
          ..then((htmlExample) => htmlExample.buildPage())
          ..then((htmlExample) => htmlExample.addListeners());
    }
    

    The class might look something like this:

    class htmlInDart {
    
      htmlInDart();
    
      Future<htmlInDart> createStyles() {
        final c = new Completer();
        // create some styles
        c.complete(this);
        return c.future;
      }
    
      Future<htmlInDart> buildPage() {
        final c = new Completer();
        // build the page
        c.complete(this);
        return c.future;
      }
    
      Future<htmlInDart> addListeners() {
        final c = new Completer();
        // add some listeners
        c.complete(this);
        return c.future;
      }
    

    Hopefully this gives you some idea of how to implement it for your case.

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

Sidebar

Related Questions

I have following HTML table: <form method=post action=update-table.php> <table class=table-data style=width: 960px;> <thead> <tr>
I have the following HTML code : <table class=report width=100%> <thead> </thead> <tbody> <tr
I have the following html code: <form> <table> <tbody> <tr> <td> <span>Quantity<span class=pull-right>3</span> <input
I have the following HTML: <div style=30px;> <table width=100%;> <tr> <td> <SELECT name=guidelinks> <OPTION
I have a html table with the following structure: <table> <thead> <tr><th>ABC Ltd.</th><tr> </thead>
Right now I have the following html table: <table id=datatable> <thead> <th>fruits</th> <th>vegs</th> </thead>
I have the following html table element: <table class='myTable'> <tbody> <tr> <th>header1</th> <td>data1</td> </tr>
I have the following HTML <form action=sendform.php method=post id=monogramming-builder> <fieldset> <table> <tr> <th>Qty</th> <th>Colour</th>
I have following table in view: # views/students/index.html.haml %table.table %thead %tr %th=t :first_name #
I have the following html table <table id={64ED3A94-5833-4CC7-869F-CCE583B498BE} class=ms-listviewtable width=100% cellspacing=0 cellpadding=1 border=0 xmlns:o=urn:schemas-microsoft-com:office:office

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.