Skip to content

Instantly share code, notes, and snippets.

@MarcSkovMadsen
Last active December 29, 2021 05:18
Show Gist options
  • Save MarcSkovMadsen/6e49383abbedce3ff073919a5558a3c0 to your computer and use it in GitHub Desktop.
Save MarcSkovMadsen/6e49383abbedce3ff073919a5558a3c0 to your computer and use it in GitHub Desktop.
//Formatter to generate line chart
var lineFormatter = function(cell, formatterParams, onRendered){
onRendered(function(){ //instantiate sparkline after the cell element has been aded to the DOM
$(cell.getElement()).sparkline(cell.getValue(), {width:"100%", type:"line", disableTooltips:true});
});
};
//generate bar chart
var barFormatter = function(cell, formatterParams, onRendered){
onRendered(function(){ //instantiate sparkline after the cell element has been aded to the DOM
$(cell.getElement()).sparkline(cell.getValue(), {width:"100%", type:"bar", barWidth:14, disableTooltips:true});
});
};
//generate discrete chart
var tristateFormatter = function(cell, formatterParams, onRendered){
onRendered(function(){ //instantiate sparkline after the cell element has been aded to the DOM
$(cell.getElement()).sparkline(cell.getValue(), {width:"100%", type:"tristate", barWidth:14, disableTooltips:true});
});
};
//generate box plot
var boxFormatter = function(cell, formatterParams, onRendered){
onRendered(function(){ //instantiate sparkline after the cell element has been aded to the DOM
$(cell.getElement()).sparkline(cell.getValue(), {width:"100%", type:"box", disableTooltips:true});
});
};
Tabulator.moduleBindings["format"].formatters['spark_line'] = lineFormatter
Tabulator.moduleBindings["format"].formatters['spark_bar'] = barFormatter
Tabulator.moduleBindings["format"].formatters['spark_tristate'] = tristateFormatter
Tabulator.moduleBindings["format"].formatters['spark_box'] = boxFormatter
var lineFormatter=function(t,e,a){a(function(){$(t.getElement()).sparkline(t.getValue(),{width:"100%",type:"line",disableTooltips:!0})})},barFormatter=function(t,e,a){a(function(){$(t.getElement()).sparkline(t.getValue(),{width:"100%",type:"bar",barWidth:14,disableTooltips:!0})})},tristateFormatter=function(t,e,a){a(function(){$(t.getElement()).sparkline(t.getValue(),{width:"100%",type:"tristate",barWidth:14,disableTooltips:!0})})},boxFormatter=function(t,e,a){a(function(){$(t.getElement()).sparkline(t.getValue(),{width:"100%",type:"box",disableTooltips:!0})})};Tabulator.moduleBindings.format.formatters.spark_line=lineFormatter,Tabulator.moduleBindings.format.formatters.spark_bar=barFormatter,Tabulator.moduleBindings.format.formatters.spark_tristate=tristateFormatter,Tabulator.moduleBindings.format.formatters.spark_box=boxFormatter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment