Skip to content

Instantly share code, notes, and snippets.

@vijaywm
Created January 15, 2021 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijaywm/34c3c9a0deb81de9460d6efbfab45b00 to your computer and use it in GitHub Desktop.
Save vijaywm/34c3c9a0deb81de9460d6efbfab45b00 to your computer and use it in GitHub Desktop.
prepare_report_data(data) {
this.data = data;
// prepare columns
this.data.columns.forEach((t) => {
t.title = t.label;
t.field = t.fieldname;
});
// set column cell formatter for known fieldtypes, if not provided already in report_settings
// list of Tabulator formatters: http://tabulator.info/docs/4.9/format
this.data.columns.forEach((col) => {
if (!col.formatter) {
this.set_column_formatter(col);
}
});
}
set_column_formatter(col) {
if (!col.fieldtype || col.fieldtype == "") {
if (
this.data &&
this.data.result &&
this.data.result.length &&
frappe.utils.is_html(this.data.result[0][col.fieldname])
)
col.formatter = "html";
} else if (col.fieldtype == "Link") {
col.formatter = function (cell) {
return `<a href='desk#Form/${
col.options
}/${cell.getValue()}'>${cell.getValue()}</a>`;
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment