我有一个带有AJAX的Datatables表: https://datatables.net/examples/data_sources/ajax.html 使用这个类: https://github.com/DataTables/DataTables/blob/master/examples/server_side/scripts/ssp.class.php
这是我的控制器:
$whereResult = "";
if(isset($_POST['provider_id'])) {
$whereResult.= "provider = ".$_POST['provider_id']['value'];
}
$table = 'providers_catalog';
$primaryKey = 'id';
$columns = array(
array( 'db' => 'product_id', 'dt' => 0 ),
array( 'db' => 'provider', 'dt' => 1 ),
array( 'db' => 'sku', 'dt' => 2 ),
array( 'db' => 'description', 'dt' => 3 )
);
echo json_encode(
SSP::complex( $_GET, $table, $primaryKey, $columns, $whereResult, $whereAll = null )
);
在我看来,我尝试进行另一次AJAX调用,但它没有为表充电:
$('#provider_id').change(function () {
var txt = {value: $(this).val(), column: "" + $(this).attr('id') + "" };
if(txt != '') {
$.ajax({
url: "Catalog/paginate",
method:"post",
data:{provider_id:txt},
dataType:"text",
success:function(data) {
},error:function () {
alert("Error");
}
});
}
});
默认的AJAX数据表具有在任何列中查找的输入搜索,然后为表重新充电,但与所有组件集成。如何为数据库的每一列创建自定义搜索字段?
答案 0 :(得分:0)
像这样调试你的代码
控制器:
<?php echo "reached controller"; ?>
查看:
$.ajax({
url: "controller_location",
method:"POST",
data:({provider_id:txt}),
success:function(data) {
alert("Success : "+data);
},
error:function () {
alert("Error : "+data);
}
});
希望这有帮助:)
答案 1 :(得分:0)
用这个插件解决了: https://datatables.net/examples/api/multi_filter.html 谢谢大家