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?可以把多个实例存储的数据分隔开。

还不知道怎么用。

时间: 2024-08-05 19:34:17

handsontable-developer guide-load and save的相关文章

load、save方法、spark sql的几种数据源

load.save方法的用法 DataFrame usersDF = sqlContext.read().load("hdfs://spark1:9000/users.parquet");                usersDF.select("name", "favorite_color").write()                .save("hdfs://spark1:9000/namesAndFavColors.pa

Ehcache(2.9.x) - API Developer Guide, Write-Through and Write-Behind Caches

About Write-Through and Write-Behind Caches Write-through caching is a caching pattern where writes to the cache cause writes to an underlying resource. The cache acts as a facade to the underlying resource. With this pattern, it often makes sense to

Ehcache(2.9.x) - API Developer Guide, Key Classes and Methods

About the Key Classes Ehcache consists of a CacheManager, which manages logical data sets represented as Caches. A Cache object contains Elements, which are essentially name-value pairs. You can use Cache objects to hold any kind of data that you wan

Ehcache(2.9.x) - API Developer Guide, Class Loading

About Class Loading Class loading, within the plethora of environments that Ehcache can be running, could be complex. But with Ehcache, all class loading is done in a standard way in one utility class: ClassLoaderUtil. Plugin Class Loading Ehcache al

Ehcache(2.9.x) - API Developer Guide, Cache Extensions

About Cache Extensions Cache extensions are a general-purpose mechanism to allow generic extensions to a cache. Cache extensions are tied into the cache lifecycle. For that reason, this interface has the lifecycle methods. Cache extensions are create

Ehcache(2.9.x) - API Developer Guide, Cache Eviction Algorithms

About Cache Eviction Algorithms A cache eviction algorithm is a way of deciding which element to evict when the cache is full. In Ehcache , the memory store and the off-heap store might be limited in size. When these stores get full, elements are evi

Ehcache(2.9.x) - API Developer Guide, Cache Manager Event Listeners

About CacheManager Event Listeners CacheManager event listeners allow implementers to register callback methods that will be executed when a CacheManager event occurs. CacheManager listeners implement the CacheManagerEventListener interface. The even

Ehcache(2.9.x) - API Developer Guide, Cache Loaders

About Cache Loaders A CacheLoader is an interface that specifies load() and loadAll() methods with a variety of parameters. CacheLoaders are incorporated into the core Ehcache classes and can be configured in ehcache.xml. CacheLoaders are invoked in

Intel® Threading Building Blocks (Intel® TBB) Developer Guide 中文 Parallelizing Data Flow and Dependence Graphs并行化data flow和依赖图

https://www.threadingbuildingblocks.org/docs/help/index.htm Parallelizing Data Flow and Dependency Graphs In addition to loop parallelism, the Intel® Threading Building Blocks (Intel® TBB) library also supports graph parallelism. It's possible to cre

Ehcache(2.9.x) - API Developer Guide, Blocking and Self Populating Caches

About Blocking and Self-Populating Caches The net.sf.ehcache.constructs package contains some applied caching classes which use the core classes to solve everyday caching problems. Two of these are BlockingCache and SelfPopulatingCache. Blocking Cach