0

I am trying to tap into the click event for when one of the paging buttons on the Datatable is clicked, but not sure how I will achieve this in Angular.

I if I look at this example, how will I possibly write the same code in Angular, and within the click event, emit an event through an @Output property, so that my parent component can be notified that an paging event fired?

2
  • Are you using jquery datatable in your angular project? Commented Nov 8, 2018 at 12:43
  • yes I am... Thinking about replacing it with ag-grid Commented Nov 8, 2018 at 14:06

2 Answers 2

1

If you want to handle the click event in the in the component where you initialized the datatable, there is no need to emit the event. Simply use the code in the example you provided in the component and your event will work just fine.

Here i have created an angular version of the example you provided. Click on next on the datatable paginator and you will see the event firing.

However if you want to handle the event in the parent component of the component where you initialized the datatable, you need emit and event through @Output and handle it in child component. Or you can use any other component interaction technique that may suite your logic.

Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

I am still learnign Angular, did not know I will be able to access the Datatable with that example, guess I should have tried... Thank for your efforts :-)
1

After trying the above solutioin provided, it did not exactly work for me.

I had to change the implementation provided, as follow:

drawCallback: () => {
          $(document).on('click', '#datatables_next', () => {
            this.nextClicked.emit("continuation");
          });
          $(document).on('click', '#datatables_previous', () => {
            console.log('next clicked...');
          });
        }

The problem is, with the provided solution, my events were never fired. This is due to the fact that the pagination controls are loaded dynamically I think, and at time of me trying to bind to those controls, they were not there.

Comments

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.