1

I use the Angular datatables module. https://github.com/l-lin/angular-datatables

I try add the processing.dt event, but it does not work.

This is the original code from the base api https://datatables.net/reference/event/processing

$('#example')
    .on( 'processing.dt', function ( e, settings, processing ) {
        $('#processingIndicator').css( 'display', processing ? 'block' : 'none' );
    } )
    .dataTable();

And this is my unworked code

.withOption('processing.dt', function( e, settings, processing){
           console.log(processing);
           $scope.loading = processing;
           }) .withOption('initComplete', function(){
                $scope.loading = false;
           })

1 Answer 1

4

There is no difference in using the dataTables events when dealing with angular datatables. If you have a table

<table datatable dt-options="dtOptions" dt-columns="dtColumns" id="example">

then this works [ http://plnkr.co/edit/hBDjR9ytD0hK6YgwrgMd?p=preview ]

$('#example').on('processing.dt', function() {
   console.log('processiong.dt');
})

and this works [ http://plnkr.co/edit/zKYyrneXl2YudNTXZkXv?p=preview ]

angular.element('#example').on('processing.dt', function() {
   console.log('processiong.dt');
})

If you use a dtInstance you can even attach event listeners to that too (here waiting for dtInstance to be initialised, then attaching a order.dt handler [ http://plnkr.co/edit/DJa1xwzxArrWhplDY278?p=preview ]) :

$scope.dtInstance = {}    

$scope.$watch('dtInstance', function() {
    if ($scope.dtInstance.DataTable) {
        $scope.dtInstance.DataTable.on('order.dt', function() {
           console.log('order.dt')
        })
    }
})  

Just to demonstrate that there is no particular "angular datatables" way of handling events, it is basically the exact same - you just have a few more options since you also have the angular.element() way and can work on the special dtInstance object.

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

1 Comment

angular.element('#cart_activity_table').on('processing.dt', function( e, settings, processing){ $scope.loading = processing; }); worked

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.