Use ajax.reload() and pass in variables

Use ajax.reload() and pass in variables

jimkielyjimkiely Posts: 9Questions: 10Answers: 0

Is there a way to use the ajax.reload() and pass in new variables? The variables will be set from dropdownlist outside of the grid.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,552Questions: 1Answers: 10,476 Site admin

    Not directly, but ajax.data can be given as a function which will be executed when you call ajax.reload() so you could pass parameters in from the function.

    Allan

  • jimkielyjimkiely Posts: 9Questions: 10Answers: 0

    Allan, I want to reload the table and pass in a new variable value (appYear: "2001"). What is the best way to do this?

  • allanallan Posts: 63,552Questions: 1Answers: 10,476 Site admin

    Probably to use the ajax.data option as I mentioned. You would need to do it in a function so it is evaluated on each request. There are examples in the ajax.data documentation.

    Allan

  • jimkielyjimkiely Posts: 9Questions: 10Answers: 0

    Any good examples of how to do a reload and pass variables?

  • allanallan Posts: 63,552Questions: 1Answers: 10,476 Site admin
    Answer ✓

    The examples on the ajax.data page should cover this do they not?

    $('#example').dataTable( {
      "ajax": {
        "url": "data.json",
        "data": function ( d ) {
            d.extra_search = $('#extra').val();
        }
      }
    } );
    

    and then just call ajax.reload(). In that case it is getting the variable front he DOM, but you can get it from anywhere you want - a function, another variable, etc.

    Allan

  • jimkielyjimkiely Posts: 9Questions: 10Answers: 0

    Thanks Allan.

This discussion has been closed.