Extra parameters for editor on create or edit

Extra parameters for editor on create or edit

whitedaywhiteday Posts: 2Questions: 1Answers: 0

Hi,

I've been trying to add extra parameters as above for the editor to send to the server whenever a new item is created or one is edited. There are quite a few examples showing how to add extra parameters, but this only seems to work for the initial GET of the table on the page load. I need to do it for editing. Thanks

Answers

  • whitedaywhiteday Posts: 2Questions: 1Answers: 0

    Never mind, I think I've figured it out. I can either pass parameters in the actual querystring (e.g. /api/staff?TestParam=100). This seems a bit messy.

    A second way is maybe using the data parameter for ajax. E.g. :

    $(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
    ajax: {
    url: "/api/staff",
    data: { "TestParam": "100" }
    }, ...

    However "TestParam" is always null in the request for some reason, even though I can see that it's been posted ok in Firebug.

  • allanallan Posts: 63,350Questions: 1Answers: 10,443 Site admin

    Its easiest to use ajax.data as a function with Editor:

    ajax: {
      url: ...,
      data: function ( d ) {
        d.TestParam = 100;
      }
    }
    

    Allan

  • allanallan Posts: 63,350Questions: 1Answers: 10,443 Site admin

    I only just fully registered this part:

    However "TestParam" is always null in the request for some reason, even though I can see that it's been posted ok in Firebug.

    How are you trying to access it? $_POST['TestParam'] would be the way in PHP. Are you using PHP or .NET or something else?

    Allan

This discussion has been closed.