1

I have yajra datatable which is working properly.

below is my datatable function

        $.ajaxSetup({
            headers:{'X-CSRF-TOKEN' : '{{ csrf_token() }}'}
        });
        
        var table = $('#tblOrderList').DataTable({
            "aaSorting": [],
            destroy:true,
            "pageLength": 25,
            processing: true,
            serverSide: true,
            ajax: {
                url:'{{ route("admin.VirtualOrderCreditBin.getVirtualCreditOrders") }}',
                method:'post'
            },
            columns : [
                {data : 'order_number', name : 'orders.order_number'},                   
                {data : 'location_description', name : 'location_description'},           
                {data : 'customer_name', name : 'customer_name'}
            ]
        });

and now I want to add click events on table rows. I want to do different functionalities on right click event, left click event and duble click event.

for that I have tried below code

    $(document).ready(function(){
        $('#tblOrderList tbody tr').mousedown(function(event) {
            switch (event.which) {
                case 1:
                    alert('Left mouse button is pressed');
                    break;
                case 2:
                    alert('Middle mouse button is pressed');
                    break;
                case 3:
                    alert('Right mouse button is pressed');
                    break;
                default:
                    alert('Nothing');
            }
        });
    });

but this is not working I don't know why.

can anybody help me in this?

Mohini
  • 476
  • 3
  • 13
  • Given that the content of the datatable is loaded using AJAX you need to use delegated event handler. See the duplicate question for more details on this. – Rory McCrossan Apr 23 '21 at 11:15

0 Answers0