我在jsGrid中有一个网格,每5秒刷新一次。虽然过滤很好并且仍在刷新,但排序表却没有。一旦刷新命中表自动返回其未排序的默认顺序。
有没有办法让JsGrid在刷新时保持排序?
这是我的代码:
$("#jsGrid").jsGrid({
height: "300px",
width: "100%",
filtering: true,
sorting: true,
paging: true,
autoload: true,
pageSize: 10,
controller: {
loadData: function(filter) {
var data = $.Deferred();
$.ajax({
type: "GET",
url: BASE_URL,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
//SUCCESS MESSAGE
},
error: function(textStatus, errorThrown) {
//ERROR MESSAGE
}
}).then(function(result) {
result = $.grep(result,
function(item) {
return //FILTERED RESULTS;
});
data.resolve(result);
});
return data.promise();
}
},
//SAMPLE FIELDS
fields: [{
name: "Name",
type: "text",
width: 150
},
{
name: "Age",
type: "number",
width: 50
},
{
name: "Address",
type: "text",
width: 200
},
{
name: "Country",
type: "select",
}
]
});
setInterval(function() {
//Refreshes grid only after 5 seconds
$("#jsGrid").jsGrid("loadData");
}, 5000);
答案 0 :(得分:2)
找到答案!昨天在GitHub上发布了一个帖子,寻找与我相同的人:
答案在我的setInterval
函数内部调用.done
函数并在那里调用jsGrid排序器。 :
setInterval(function() {
//Refreshes grid only after 5 seconds
$('#jsGrid').jsGrid("loadData").done(function () {
var sorting = $("#jsGrid").jsGrid("getSorting");
$("#jsGrid").jsGrid("sort", sorting);
}, 5000);