制表符每 x 秒刷新 table
Tabulator refresh table every x seconds
我有以下代码。它从外部 URL 获取 JSON 数据并将其加载到 Tabulator。
<html>
<head>
<link href="dist/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="dist/js/tabulator.min.js"></script>
</head>
<body>
<div id="example-table"></div>
<script type="text/javascript">
const url = "http://85.17.219.9/test.json";
var table = new Tabulator("#example-table", {
ajaxConfig:{
method: 'GET'
},
ajaxURL: url,
index:"MessageID",
autoResize:true,
layout:"fitColumns", //layout options
placeholder:"Awaiting Data...",
columns:[
{title:"timestamp", field:"timestamp", headerSort:false},
{title:"latitude", field:"latitude", headerSort:false},
{title:"longtitude", field:"longtitude", headerSort:false},
],
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; //pass the data array into Tabulator
},
});
table.setSort("latitude", "asc")
</script>
</body>
</html>
它工作正常。 JSON 数据每 x 秒更改一次。我想每 x 秒重新加载 table。如何在不重新加载整个页面的情况下实现此目的?
我是新手 JS/Tabulator...
我相信你应该能够通过 setInterval
和 table.replaceData()
的组合来做到这一点。
setInterval(() => table.replaceData(), yourInterval);
我有以下代码。它从外部 URL 获取 JSON 数据并将其加载到 Tabulator。
<html>
<head>
<link href="dist/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="dist/js/tabulator.min.js"></script>
</head>
<body>
<div id="example-table"></div>
<script type="text/javascript">
const url = "http://85.17.219.9/test.json";
var table = new Tabulator("#example-table", {
ajaxConfig:{
method: 'GET'
},
ajaxURL: url,
index:"MessageID",
autoResize:true,
layout:"fitColumns", //layout options
placeholder:"Awaiting Data...",
columns:[
{title:"timestamp", field:"timestamp", headerSort:false},
{title:"latitude", field:"latitude", headerSort:false},
{title:"longtitude", field:"longtitude", headerSort:false},
],
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; //pass the data array into Tabulator
},
});
table.setSort("latitude", "asc")
</script>
</body>
</html>
它工作正常。 JSON 数据每 x 秒更改一次。我想每 x 秒重新加载 table。如何在不重新加载整个页面的情况下实现此目的?
我是新手 JS/Tabulator...
我相信你应该能够通过 setInterval
和 table.replaceData()
的组合来做到这一点。
setInterval(() => table.replaceData(), yourInterval);