【问题标题】:HandsonTable sort data by loading from ajaxHandsonTable 通过从 ajax 加载对数据进行排序
【发布时间】:2016-01-02 09:43:49
【问题描述】:

我尝试使用 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
});

【问题讨论】:

    标签: javascript php jquery ajax handsontable


    【解决方案1】:

    您可以做的是禁用排序插件,然后单击标题,向您的后端发送包含数据和排序参数的请求。在那里做任何你想做的排序,然后在你的hotInstance 上返回新的data 对象和updateSettings,如下所示:

    hotInstance.updateSettings({
        data: newData
    })
    

    有了这个,你应该准备好了。

    【讨论】:

    • 但是。我怎样才能让 whick colum 排序?
    • 只检查你点击的标题的值是什么。取决于您如何激活该点击事件。
    猜你喜欢
    • 2017-11-24
    • 2015-01-24
    • 2010-10-31
    • 1970-01-01
    • 2012-11-03
    • 2020-07-03
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    相关资源
    最近更新 更多