3

on my page i have dataTable, which was initialized with, for example, sAjaxSource url like "/api/reports". when we're doing sorting, filtering it appends to url additional query-keys. I want do add keys "date_from" and "date_to" to sAjaxSource url (date intervals could be changed after table initialization). is there any entry-point function, before table reload, so i can do there smth like:

var oSettings = rtbl.fnSettings();
oSettings.sAjaxSource = "/api/reports/?type=sites&date_from=" + $("#date_from").text() + "&date_to=" + $("#date_to").text();

thanks for your help!

2 Answers 2

3

so, i've solved it, by next, quite dummy, way:

function set_sAjaxSource(){
                var oSettings = rtbl.fnSettings();
                oSettings.sAjaxSource = "/api/reports/?type=sites&date_from=" + $("#date_from").val() + "&date_to=" + $("#date_to").val();
            }

            $('.sorting').bind('click', set_sAjaxSource)
            $('.sorting_asc').bind('click', set_sAjaxSource)
            $('.sorting_desc').bind('click', set_sAjaxSource)
            $('.sorting_desc').bind('click', set_sAjaxSource)
            $('.paginate_button').bind('click', set_sAjaxSource)
            $('.sorting_active').bind('click', set_sAjaxSource)
Sign up to request clarification or add additional context in comments.

Comments

2

The correct way to do this to use the fnServerParams function of datatables, when creating the table:

fnServerParams: function(aoData) {
              aoData.push({ name: "type", value: 'sites' });
              aoData.push({ name: "date_from", value: $("#date_from").text() });
              aoData.push({ name: "date_to", value: $("#date_to").text() });
            }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.