handsontable-developer guide-cell function

renderer

展示的数据不是来自于数据源,而是先把DOM和其他信息传给renderer,然后展示。

//五种展示函数
TextRenderer: default
NumericRenderer
AutocompleteRenderer
CheckboxRenderer
PasswordRenderer

自己不能给cell加listener的原因:1、一个cell会多次调用renderer,可能会导致它有多个相同事件监听器;2、cell CRUD scrolling,可能导致cell和listener绑定错误。如果一定要这样做,需要把cell content放在div中,给div加监听器

renderer函数 尽可能的快和简洁

editor

validator

可以是函数或者regex;与renderer和editor相比,validator不需要为每个元素都定义。

renderer,editor,validator是相互联系的

handsontable定义了一些type,来系列化这三个函数,好处如下:

var hot = new Handsontable(document.getElementById(‘container‘), {
  columns: [
    {
      renderer: Handsontable.NumericRenderer,
      editor: Handsontable.editors.TextEditor,
      validator: Handsontable.NumericValidator
    }
  ]
});

var hot = new Handsontable(document.getElementById(‘container‘), {
  columns: [
    {
      type: ‘numeric‘
    }
  ]
});

预定义的类型

text
numeric
date
checkbox
password
select
dropdown
autocomplete
handsontable
//function的优先级高于typevar hot = new Handsontable(document.getElementById(‘container‘), {
  columns: [
  {
    type: ‘numeric‘,
    validator: customValidator // validator function defined elsewhere
  }
]
});
//type=‘password‘没有定义validator,比函数更特殊。var hot = new Handsontable(document.getElementById(‘container‘), {
  validator: customValidator, // validator function defined elsewhere
  columns: [
    {
      type: ‘password‘
    },
    {}
  ]
});
相当于
var hot = new Handsontable(document.getElementById(‘container‘), {
  columns: [
    {
      renderer: Handsontable.PasswordRenderer,
      editor: Handsontable.editors.PasswordEditor,
      validator: undefined
    }
    {
      renderer: Handsontable.TextRenderer, // text cell type is the default one
      editor: Handsontable.editors.TextEditor, // text cell type is the default one
      validator: customValidator
    }
  ]
});
//通过function定义的才可以,如果通过type定义的,则返回undefinedvar cellProperties = $(‘#container‘).handsontable(‘getCellMeta‘, 0, 0);
// get cell properties for cell [0, 0]
cellProperties.renderer; // get cell renderer
cellProperties.editor; // get cell editor
cellProperties.validator; // get cell validator
//通过function或者type定义的都可以getCellRenderer(row, col)
getCellEditor(row, col)
getCellValidator(row, col)

  

时间: 2024-08-01 07:46:35

handsontable-developer guide-cell function的相关文章

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, 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, 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, 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

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

About Exception Handlers By default, most cache operations will propagate a runtime CacheException on failure. An interceptor, using a dynamic proxy, may be configured so that a CacheExceptionHandler can be configured to intercept Exceptions. Errors

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

About Cache Decorators Ehcache uses the Ehcache interface, of which Cache is an implementation. It is possible and encouraged to create Ehcache decorators that are backed by a Cache instance, implement Ehcache and provide extra functionality. The Dec

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

About Cache Event Listeners Cache listeners allow implementers to register callback methods that will be executed when a cache event occurs. Cache listeners implement the CacheEventListener interface. The events include: An Element has been put An El