我正在使用Tabulator插件在jsp页面内为我处理表和排序。当我在标签内使用数据表时,它工作正常。我现在正尝试从我们使用的系统返回AJAX数据。以下是系统返回的json的示例。
如何配置Tabulator使用数据并跳过响应的“平台”部分?
JSP脚本 桌子
<script>
//Build Tabulator
var table = new Tabulator("#example-table", {
height:"311px",
layout:"fitColumns",
placeholder:"No Data Set",
columns:[
{title:"PO", field:"po_number", sorter:"string", width:200},
],
});
//trigger AJAX load on "Load Data via AJAX" button click
$("#ajax-trigger").click(function(){
table.setData("https://mysystem.com/record/fieldList=po_number&alt=json");
});
</script>
JSON响应:
{“平台”:{ “信息”: { “代码”:“ 0”, “描述”:“成功” }, “记录”:[ {“ po_number”:“ P000466”}, {“ po_number”:“ P000791”}, ], “ recordCount”:“ 2” }}
答案 0 :(得分:0)
您可以使用 ajaxResponse 回调更改响应,然后再将其传递到表中进行处理。
我假设您要传递 记录 属性:
var table = new Tabulator("#example-table", {
height:"311px",
layout:"fitColumns",
placeholder:"No Data Set",
columns:[
{title:"PO", field:"po_number", sorter:"string", width:200},
],
ajaxResponse:function(url, params, response){
//url - the URL of the request
//params - the parameters passed with the request
//response - the JSON object returned in the body of the response.
return response.record; //return the recordproperty of a response json object
},
});
我希望能帮上忙,
欢呼
Oli:)
答案 1 :(得分:0)
$.ajax({
url : "{{url_for('foo')}}",
data: {fooid:fooid},
type: 'GET',
contentType: "application/json;",
success: function(receipts){var obj = $.parseJSON(receipts);
var table = new Tabulator("#user-project-table", {
layout:"fitData",
data:obj,
etc,
etc,
etc...
},
error: function(error){
console.log(error);
}