How to dynamically pass parameters to server datasource

How to dynamically pass parameters to server datasource

vbulashvbulash Posts: 9Questions: 3Answers: 0

Server-side datasource init once by the similar code:

serverSide: true,
ajax: '{!! route('scales.index.data') !!}',

Here I can put static filtering.
Then I'd like to change filter input and pass parameters to server on-the-fly.
Unfortunately, datatable draw() function doen't provide ability to pass parameters.
How to it?

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 3,021Questions: 88Answers: 421
    Answer ✓

    Like this for example:

    ajax: {
        url: 'yourURL',
        type: 'POST',
        data: function ( d ) {            
            d.postVariable = yourVariable;
            d.fullTextSearchString = d.search.value;
        }
    },
    

    Then in PHP you can address it as $_POST['postVariable'] and $_POST['fullTextSearchString'].

  • vbulashvbulash Posts: 9Questions: 3Answers: 0

    Thanks a lot!
    It works!

Sign In or Register to comment.