Custom search fields in datatables

Custom search fields in datatables

tuytooshtuytoosh Posts: 2Questions: 1Answers: 0
edited January 2017 in Free community support

Hi all, I want to add some custom fields that they are not in table and stored in MySQL database, for example and in a simple word I have a ref_code filed in database that not shows in table... I want to add a 'Reference code' field... my problem is how to send custom search field value in every table draw()

my code is like below :

       var table = $('#my-table').DataTable({
                serverSide: true,
                ajax:{
                    "url" : '{{ url('user/transaction/ajax') }}',
                    "data" : {
                        "type" : '{{ $type }}',
                        "id" : '{{ $id }}',
                        "ref_code" : $('#ref_code').val()
                    }
                } ,
            });

            $('#ref_code').keyup( function() {
                table.draw();
            } );

This code sends empty variable as ref_code in every ajax request...

Answers

  • tuytooshtuytoosh Posts: 2Questions: 1Answers: 0

    I find my answer :smile:

    var table = $('#my-table').DataTable({
             serverSide: true,
             ajax:{
                 "url" : '{{ url('user/transaction/ajax') }}',
                "data" : function (d) {
                            d.id = '{{ $id }}';
                            d.type = '{{ $type }}';
                            d.ref_code = $('#ref_code').val();
                        }
             } ,
         });
     
         $('#ref_code').keyup( function() {
             table.draw();
         } );
    

    I hope this helps someone else...

This discussion has been closed.