我尝试使用Handsontable插件,并希望通过使用ajax对表上的数据进行排序。
当我使用columnSorting: true
时,视图上只有排序,我更新它出错的索引行。
谁知道如何从php排序数据,然后在表上排序后显示数据结果?
$container.handsontable({
colHeaders: header(),//["Title", "Description", "Comments"],
data : data(),
//startRows: 3,
columnSorting: true,
startCols: 20,
rowHeaders: true,
colHeaders: true,
minSpareRows: 1,
contextMenu: true,
copyRowsLimit: 100000,
beforeChange: function (change, source) {
if (source === 'loadData') {
return; //don't save this change
}
if ($('input[name=autosave]').is(':checked')) {
$("#dataconsole").html("<p>Please wait ...</p>").hide().fadeIn("slow");
clearTimeout(autosaveNotification);
$.ajax({
url: "../php/save_auto.php?cmid=<?php echo $com_id;?>",
type: "POST",
data: {"changes": change}, //contains changed cells' data
success: function (data) {
$("#dataconsole").text('Autosaved (' + change.length + ' cell' + (change.length > 1 ? 's' : '') + ')');
if(source !== 'program'){
// reset current cell
$( "td:contains('=')").text(data);
}
}//complete
});
}//checked
}//change
});
你可以做的是禁用排序插件,点击标题,向你的后端发送一个带有数据和排序参数的请求。在那里做任何你想要的排序,然后在hotInstance
上返回新的data
对象和updateSettings
,如下所示:
hotInstance.updateSettings({
data: newData
})