question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

multiple angular datatable components has some problem when use column click event

See original GitHub issue
  • angular version:Angular 4.3
  • angular-datatables version:4.2.0

What’s the problem?

Hi , i have a problem when i have multiple angular components which use datatable and add row click event. For example:A component has a event handler name aHander() , and B component has a event handler named bHander(), when i start A component and click the row will trigger aHander(), but when i navigate the router to B component and click the row button ,it will trigger the aHandler() not bHandler() !!!, so can you help me solve this problem, in my project has many components which use datatable and have CURD buttons to trigger different handlers. Thanks

Can you share your code?

Here is datatable extention column definition:

{
        "data":null,
        "title":"Option",
        "searchable":false,
        "orderable":false,
        "width":'15%',
        "render":function(data, type, row, meta){
            let html = '<div class="btn-group btn-overlap btn-corner">'+
                                '<a class="btn btn-info btn-sm edit" title="Edit">'+
                                    '<i class="fa fa-pencil"></i>'+
                                 '</a>&nbsp;'+
                               '<a class="btn btn-danger btn-sm delete title="Delete">'+
                                    '<i class="fa fa-trash-o"></i>'+
                               '</a>&nbsp;'+
                           '</div>';
            return html;
        }
    }

and follow code define the edit、delete button trigger event:

this.dtOptions["createdRow"] =(row, data, dataIndex) =>{
            const self = this;
            let editDom:any = $(row).find(".edit");
            editDom.unbind('click');
            editDom.bind('click', () => {
                self.updateAction(data);
                
              });
            
            let deleteDom = $(row).find(".delete");
            deleteDom.unbind('click');
            deleteDom.bind('click', () => {
                self.deleteAction(data);
              });
        }

i have many angular components like this, but when i use angular route navigate to another component, it will triggers a same handler method in a component which first run all the time , so please help me …

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
l-lincommented, Oct 22, 2017

In your example, when clicking on “Edit” of component B, it will call self.updateAction(data); with the data of component A? Are you certain your dtOptions are isolated and not shared between your components?

0reactions
posly66commented, Oct 23, 2017

@l-lin With your reminding, I solved this problem! Thank you very much! The problem is that need a isolated dtOptions!

Because I have many components need to use datatable, so I put dtOption as a common public part named datatableConf, each component needs to export datatableConf firstly, then define let dtOption = datatableConf and add some column options to the dtOption .

In the final analysis, the main reason is that i don’t fully understand the characteristics of TypeScript or ES6.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues when using Angular Datatables as a shared component
Now I am facing multiple issues here : It is showing No data available in table sometimes, but when the page is refreshed,...
Read more >
rowCallback can create duplicate click handlers for the same ...
Hi ,i have a problem when i have multiple angular components which use datatable and add row click event. For example:A component has...
Read more >
Error on api.rows().select() method angular datatables
Hello everyone. Like the title says, I'm implementing datatables with the angular wrapper and in the same component I have two data tables,...
Read more >
Using Angular DataTables to build feature-rich tables
The Angular DataTables library combines Angular directives with jQuery's DataTables plugin. See how to use it in our tutorial.
Read more >
jQuery DataTables: Why click event handler does not work
Provides solution to a problem when click and other event handlers don't work on pages other than first or when table is sorted...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found