duancai1904 2015-10-05 16:41
浏览 212

HandsonTable通过从ajax加载来对数据进行排序

I try to use Handsontable plugin and want to sort data on table by using ajax .

When I use columnSorting: true, there only sorting on view and I update it goes wrong index row.

Anyone has idea how to sort data from php and then show data result after sort on table?

$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
});
  • 写回答

1条回答 默认 最新

  • douan7601 2015-10-06 17:02
    关注

    What you could do is disable the sorting plugin and on click of the header, send a request to your backend with the data and the sorting parameter. Do whatever sorting you want in there, then return the new data object and updateSettings on your hotInstance like so:

    hotInstance.updateSettings({
        data: newData
    })
    

    And with this you should be set to go.

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮