如何动态设置dataTable的Ajax URL? [英] How to set dynamically the Ajax URL of a dataTable?
本文介绍了如何动态设置dataTable的Ajax URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jQuery DataTables,我的JavaScript代码如下所示:
$(document).ready(function ){
var tbl = $('#table_tabl')。DataTable({
respond:true,
oLanguage:{
sUrl:<?php echo RP_LANG?> fr_FR.txt,
},
processing:true,
serverSide:true,
ajax:<?php echo RP_SSP? > server_processing_reservTables.php,//我想在选择select元素时动态添加一个参数表
aoColumnDefs:[{
aTargets:[3],
mData:3,
mRender:function(data,type,full){
return'< div style =text-align:center;>< a href = RestaurantReservation / reserverTable /'+ data +'title =R& eacute; server>< span class =mif-lock icon>< / span>< / a>< / div> ;
}
}],
aLengthMenu:[
[10,25,50,10 0,-1],
[10,25,50,100,Tout]
]
});
});
我想根据select元素的选定值过滤这个dataTable:
$(#select_id)。on(change,function(){
//设置ajax选项值dataTable这里根据select的值
});
如何设置 ajax
基于选择
元素的 on_change
事件中的 dataTable
在选择的选定项目上?
解决方案
我发现:
<$ p $($ s code $)$(#salle_code)on(change,function(){
tbl.ajax.url(<?php echo RP_SSP?> server_processing_reservTables.php ?salle_code =+ $(this).val())。load();
});
I'm using jQuery DataTables, my JavaScript code is shown below:
$(document).ready(function() {
var tbl = $('#table_tabl').DataTable({
responsive: true,
"oLanguage": {
"sUrl": "<?php echo RP_LANG ?>fr_FR.txt",
},
"processing": true,
"serverSide": true,
ajax: "<?php echo RP_SSP ?>server_processing_reservTables.php", // I want to add a parmeter to it dynamically when a select element is selected
"aoColumnDefs": [{
"aTargets": [3],
"mData": 3,
"mRender": function(data, type, full) {
return '<div style="text-align:center;"><a href="RestaurantReservation/reserverTable/' + data + '" title="Réserver"><span class="mif-lock icon"></span></a></div>';
}
}],
"aLengthMenu": [
[10, 25, 50, 100, -1],
[10, 25, 50, 100, "Tout"]
]
});
});
I want to filter this dataTable according to the selected value of a select element :
$("#select_id").on("change", function(){
// set the ajax option value of the dataTable here according to the select's value
});
How to set the ajax
option's value of the dataTable
in the on_change
event of the select
element based on the select's selected item ?
解决方案
I found it :
$("#salle_code").on("change", function(){
tbl.ajax.url("<?php echo RP_SSP ?>server_processing_reservTables.php?salle_code="+$(this).val()).load();
});
这篇关于如何动态设置dataTable的Ajax URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文