如果我有一个sAjaxSource,我可以通过它传递参数,使我的页面更灵活吗?我现在就是这样的:
"sAjaxSource": "Data/IndustryTable?region_type=4®ion_code=51&ind_min=10&ind_max=99"
最终目标是当用户登陆页面时预定义参数加载特定数据。用户选择更新参数后,更新数据表。
这是大部分的 准备好的功能
$(document).ready(function () {
var anOpen = [];
var oTable = $('#VADataTable').dataTable
({
// "sDom": 'T<"clear">lfrtip',
// "oTableTools":
// {
// "sSwfPath": "/swf/copy_csv_xls_pdf.swf"
// }, //flash must be enabled
"iDisplayLength": 5, //defalut amount of rows shown on page
"bServerSide": false, //uses sever for filter curently turned off
"bFilter": false, //makes columns clickable to filter
"bProcessing": true,
//"bserverSide":true,
"bJQueryUI": true, //enables user interface
"bSort": true, //sorting for columns
"bScrollInfinite": true, //using this takes away ddl of selection
"sAjaxSource": "Data/IndustryTable?region_type=4®ion_code=51&ind_min=10&ind_max=99", //where ajax commands renders results
"sScrollY": "200px",
"sScrollX": "100%",
"sScrollXInner": "100%",
"bScrollCollapse": true,
答案 0 :(得分:4)
使用您的示例代码,它看起来像这样:
$(document).ready(function () {
var anOpen = [];
var oTable = $('#VADataTable').dataTable
({
// "sDom": 'T<"clear">lfrtip',
// "oTableTools":
// {
// "sSwfPath": "/swf/copy_csv_xls_pdf.swf"
// }, //flash must be enabled
"iDisplayLength": 5, //defalut amount of rows shown on page
"bServerSide": false, //uses sever for filter curently turned off
"bFilter": false, //makes columns clickable to filter
"bProcessing": true,
//"bserverSide":true,
"bJQueryUI": true, //enables user interface
"bSort": true, //sorting for columns
"bScrollInfinite": true, //using this takes away ddl of selection
"sAjaxSource": "Data/IndustryTable", //I use a custom .aspx page for my source
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "region_type", "value": "4" },
{ "name": "region_code", "value": "51"},
{ "name": "ind_min", "value": "10"},
{ "name": "ind_max", "value": "99"} );
},
"sScrollY": "200px",
"sScrollX": "100%",
"sScrollXInner": "100%",
"bScrollCollapse": true,
...
这样的设置将传递所有正常的Datatables参数以及region_type,region_code,ind_min和ind_max。
在sAjaxSource代码中,您可以像普通(我使用VB)
一样检索这些参数 Dim RegionType As Integer = Request("region_type")
答案 1 :(得分:0)
显然fnServerParams不适用于较旧版本的Datatables。 使用PHP怎么样:
...
"bScrollInfinite": true, //using this takes away ddl of selection
"sAjaxSource": "Data/IndustryTable?region_type=<?=$_GET['region_type'];?>®ion_code=<?=$_GET['region_code'];?>&ind_min=<?=$_GET['ind_min'];?>&ind_max=<?=$_GET['ind_max'];?>", //where ajax commands renders results
"sScrollY": "200px",
...
答案 2 :(得分:-1)
他们想要使用的方式不是数据表的使用方式,因此请尝试使用fnServerParams:
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": false,
"sAjaxSource": "scripts/server_processing.php",
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "more_data", "value": "my_value" } );
}
} );