Skip to content

Instantly share code, notes, and snippets.

@gundisalwa
Created June 22, 2014 15:08
Show Gist options
  • Save gundisalwa/cdb067df2801fe5b63ca to your computer and use it in GitHub Desktop.
Save gundisalwa/cdb067df2801fe5b63ca to your computer and use it in GitHub Desktop.
Dynamic Coltype addIn
/*
* Dynamic colType (AddIn)
*
* This addIn allows a control of the addIn called on a cell basis, rather than on a
* column basis only.
*
* Options:
* - colType: 'formattedText' by default. This can be controlled by passing a state
* dependant function to the registered addIn options.
* - compName: atm the addIn needs to have access to the component where the options
* are defined, so it needs to have that component name passed.
*/
Dashboards.registerAddIn("Table", "colType", new AddIn({
name: "dynamicColType",
label: "Dynamic colType",
defaults: {
colType: "formattedText",
// TODO: find some other way to pass the component???
compName: undefined
},
init: function(){
$.fn.dataTableExt.oSort[this.name+'-asc'] = $.fn.dataTableExt.oSort['string-asc'];
$.fn.dataTableExt.oSort[this.name+'-desc'] = $.fn.dataTableExt.oSort['string-desc'];
},
implementation: function(tgt, st, opt){
if (opt.compName && Dashboards.hasAddIn('Table','colType', opt.colType)){
var comp = Dashboards.getComponentByName(opt.compName),
addIn = comp.getAddIn("colType",opt.colType),
addInOpts = comp.getAddInOptions("colType",opt.colType);
addIn.call(tgt,st,addInOpts);
$(tgt).addClass(opt.colType);
}
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment