• handsontable-developer guide-load and save


    不过handsontable不能用jquery取对象
    var
      $$ = function(id) {
        return document.getElementById(id);
      },
      container = $$('example1'),
      exampleConsole = $$('example1console'),
      autosave = $$('autosave'),
      load = $$('load'),
      save = $$('save'),
      autosaveNotification,
      hot;
    
    hot = new Handsontable(container, {
      startRows: 8,
      startCols: 6,
      rowHeaders: true,
      colHeaders: true,
      afterChange: function (change, source) {
        if (source === 'loadData') {
          return; //don't save this change
        }
        if (!autosave.checked) {
          return;
        }
        clearTimeout(autosaveNotification);
        ajax('scripts/json/save.json', 'GET', JSON.stringify({data: change}), function (data) {
          exampleConsole.innerText  = 'Autosaved (' + change.length + ' ' + 'cell' + (change.length > 1 ? 's' : '') + ')';
          autosaveNotification = setTimeout(function() {
            exampleConsole.innerText ='Changes will be autosaved';
          }, 1000);
        });
      }
    });
    
    Handsontable.Dom.addEvent(load, 'click', function() {
      ajax('scripts/json/load.json', 'GET', '', function(res) {
        var data = JSON.parse(res.response);
    
        hot.loadData(data.data);
        exampleConsole.innerText = 'Data loaded';
      });
    });
    
    Handsontable.Dom.addEvent(save, 'click', function() {
      // save all cell's data
      ajax('scripts/json/save.json', 'GET', JSON.stringify({data: hot.getData()}), function (res) {
        var response = JSON.parse(res.response);
    
        if (response.result === 'ok') {
          exampleConsole.innerText = 'Data saved';
        }
        else {
          exampleConsole.innerText = 'Save error';
        }
      });
    });
    
    Handsontable.Dom.addEvent(autosave, 'click', function() {
      if (autosave.checked) {
        exampleConsole.innerText = 'Changes will be autosaved';
      }
      else {
        exampleConsole.innerText ='Changes will not be autosaved';
      }
    });
    

    把数据保存在本地

    可在初始化或更新方法中设置persistentState为true:persistentStateSave, persistentStateLoad(把value存在valuePlaceholder.value), persistentStateReset,

    为什么要使用persistentState?可以把多个实例存储的数据分隔开。

    还不知道怎么用。

  • 相关阅读:
    Eclipse快捷键大全
    Quartz任务调度快速入门
    Spring整合logback日志
    Java实现二维码的生成与解析
    跨域问题及解决方案
    SpringBoot项目直接在linux下运行
    SpringBoot拦截器中使用RedisTemplate
    Codeforces Round #345 (Div. 1) C. Table Compression dp+并查集
    HDU 4489 The King’s Ups and Downs dp
    HDU 4747 Mex 递推/线段树
  • 原文地址:https://www.cnblogs.com/wang-jing/p/4656303.html
Copyright © 2020-2023  润新知