How can a plugin modify the ajax server params?

How can a plugin modify the ajax server params?

phazeiphazei Posts: 3Questions: 0Answers: 0
edited April 2014 in DataTables 1.10
I'm using dataTables 1.10 from the repo, 4-15

I'm trying to write a plugin that adds a dropdown with columns based on particular column options. Then whenever the data is pulled from the server, either via a filter search or reordering of the columns, I need that extra data to be sent in the data object.

I have the dropdown being created just find, but I'm not sure where to hook in to manipulate the data.

Looking through the code, I found the serverParams, but it's not documented in the 1.10 references. Is it only for compatibility? Is there a more proper place to hook into that in 1.10?

The only other think I could think of was somehow over riding the _fnAjaxParameters prototype with another function that calls it and edits it's returned data, and passes that along, which I'm not quite clear enough on the workings of js to know if it's possible or not.

Replies

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Darn - yes, I missed that in the upgrade for 1.10. I think I'll need to add a a`preAjax` event or something like that. Let me have a bit of a think on the best way of doing it and I'll get back to you.

    Allan
  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    I've added a `preXhr` option here: https://github.com/DataTables/DataTablesSrc/commit/729581eb9

    So now you can do something like:

    [code]
    $('#example').on('preXhr.dt', function ( e, s, d ) {
    d.extra = 1;
    } );
    [/code]

    Thanks for flagging this up!

    Allan
  • jsm174jsm174 Posts: 6Questions: 0Answers: 0
    edited June 2014

    I've been using this and it seems to be working well in Chrome, and FF. It does not work in IE8. I put an alert in, and it's never fired.

    _criterionTable = $("#criterion-table").on("preXhr.dt", 
    function (e, settings, data) {
           alert("HERE");
           data.eventId = "1";
         })
         .DataTable({
             stateSave: true
    .
    .
    .
    

    Am I missing something, or is this a bug?

    Thanks

    Jason

  • jsm174jsm174 Posts: 6Questions: 0Answers: 0

    I just updated to the nightly, and it's now working in IE8.

    Thanks,

    Jason

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Hi Jason,

    Great to hear that the nightly is doing the business for you. Planning to release it as 1.10.1 next week with a few other fixes in.

    Allan

This discussion has been closed.