24sharon
24sharon

Reputation: 1975

Angularjs jQuery datatables add processing event

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;
           })

Upvotes: 1

Views: 1429

Answers (1)

davidkonrad
davidkonrad

Reputation: 85528

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.

Upvotes: 4

Related Questions