Jquery dataTables plugin: dynamically changing ajaxSource

on my page I have a dataTable that has been initialized, for example, sAjaxSource url, for example, "/ api / reports". when we do the sorting, its filtering is added for the URL of the additional request keys. I want to add the keys "date_from" and "date_to" to the sAjaxSource url (date intervals can be changed after the table is initialized). is there any entry point function before reloading the table, so I can do something like there:

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

thank you for your help!

+3
source share
2 answers

fnServerParams datatables :

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() });
            }
+2

, , , , :

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)
+3

Source: https://habr.com/ru/post/1735736/


All Articles