1 var Mutator =
function(table){
3 this.allowedTypes = [
"",
"data",
"edit",
"clipboard"];
8 Mutator.prototype.initializeColumn =
function(column){
13 this.allowedTypes.forEach(
function(type){
14 var key =
"mutator" + (type.charAt(0).toUpperCase() + type.slice(1)),
17 if(column.definition[key]){
18 mutator =
self.lookupMutator(column.definition[key]);
25 params: column.definition[key +
"Params"] || {},
32 column.modules.mutate = config;
36 Mutator.prototype.lookupMutator =
function(value){
42 if(this.mutators[value]){
43 mutator = this.mutators[value];
45 console.warn(
"Mutator Error - No such mutator found, ignoring: ", value);
58 Mutator.prototype.transformRow =
function(data, type, updatedData){
60 key =
"mutator" + (type.charAt(0).toUpperCase() + type.slice(1)),
65 self.table.columnManager.traverse(
function(column){
66 var mutator, params, component;
68 if(column.modules.mutate){
69 mutator = column.modules.mutate[key] || column.modules.mutate.mutator ||
false;
71 if(mutator && updatedData){
72 value = column.getFieldValue(updatedData);
74 if(type ==
"data" || typeof value !==
"undefined"){
75 component = column.getComponent();
76 params = typeof mutator.params ===
"function" ? mutator.params(value, data, type, component) : mutator.params;
77 column.setFieldValue(data, mutator.mutator(value, data, type, params, component));
88 Mutator.prototype.transformCell =
function(cell, value){
89 var mutator = cell.column.modules.mutate.mutatorEdit || cell.column.modules.mutate.mutator ||
false,
93 tempData = Object.assign(tempData, cell.row.getData());
94 cell.column.setFieldValue(tempData, value);
95 return mutator.mutator(value, tempData,
"edit", mutator.params, cell.getComponent());
101 Mutator.prototype.enable =
function(){
105 Mutator.prototype.disable =
function(){
106 this.enabled =
false;
111 Mutator.prototype.mutators = {};
113 Tabulator.prototype.registerModule(
"mutator", Mutator);