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.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)