jquery Tables Plugin: dynamisch ändern ajaxSource
-
25-09-2019 - |
Frage
auf meiner Seite, ich habe Datatable , die mit initialisiert wurde zum Beispiel sAjaxSource URL wie „/ api / berichtet“. wenn wir das Sortieren tun, Filterung es anhängt zusätzlichen Abfrage-Schlüssel mit url. Ich will do Schlüssel „date_from“ und „DATE_TO“ zu sAjaxSource url (Datum Intervallen nach Tabelle Initialisierung geändert werden könnte). es eine Einstiegspunktfunktion, bevor Tabelle reload, so dass ich wie es smth tun können:
var oSettings = rtbl.fnSettings();
oSettings.sAjaxSource = "/api/reports/?type=sites&date_from=" + $("#date_from").text() + "&date_to=" + $("#date_to").text();
Danke für Ihre Hilfe!
Lösung
Der richtige Weg, dies zu tun, um die fnServerParams Funktion von Datentabellen zu verwenden, wenn Sie die Tabelle erstellen:
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() });
}
Andere Tipps
Also, ich habe es gelöst, indem nächste, ganz blind, Art und Weise:
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)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow