fnInitComplete don't work after column reorder

fnInitComplete don't work after column reorder

henriqueakhenriqueak Posts: 1Questions: 0Answers: 0
edited June 2016 in Free community support

Hi,
I'm new to DataTables, but I am experiencing an issue and have not found anywhere talking about this.
I am loading data to DataTable using Ajax, and after data load I want to tie an 'onclick' event to the button that exists on last column used to trigger and post call to delete the related registry from database and also remove the line from the table.
The delete button works well when you do not use column reorder or Search field on Datatable. But if you reorder any column, or filter the table data using "Search" field, the 'fnInitComplete' don work anymore, i.e., the delete button don't work.
Anyone have already experimented this?
DataTable code:

    <script>
        $(document).ready(function() {
            $('#datatable_personal').dataTable({
                "sScrollX": "100%",
                "sScrollXInner": "100%",
                "ajax": "{{ route('clidoc.en') }}",
                "deferRender": true,
                "fnInitComplete": function (oSettings) {
                    <!-- Deletion -->
                    $('.exclude').on('click', function(){
                        var id = this.id;
                        $.post('/clidoc/de', {
                            'id'    : id,
                            '_token': '{{ csrf_token() }}'
                        }, function (data, status) {
                            $('#exclude'+id).remove();
                            new PNotify({
                                title: 'Exclusão',
                                text: 'Exclusão da solicitação efetuada com sucesso!',
                                type: 'success',
                                styling: 'bootstrap3'
                            });
                        });
                    });
                },
            });
        });
   </script>

Replies

  • allanallan Posts: 63,230Questions: 1Answers: 10,417 Site admin

    This sounds a lot like the second top FAQ. It might not be exactly the same, but I would very much encourage you to use delegated events as that FAQ answer suggests, otherwise you will run into that issue on the second page, and I believe it will resolve this as well.

    Allan

This discussion has been closed.