ERPNext Conference 2019* ERPNext.com Blog

Error in colouring Script reports


#1

I am trying to add colour to the text of each cell. I am using the following code :

"formatter":function (row, cell, value, columnDef, dataContext, default_formatter) {
		value = default_formatter(row, cell, value, columnDef, dataContext);
			 if(columnDef.id == "Status"){
				value = "<span style='color:blue;font-weight:bold';>" + value + "</span>";
			}
		return  value;
}

Im getting this error:


How to change color of select field?
[Tutorial] Add Color to Cells in Query Report
#2

It seems you are applying color changes in custom report. Is it script report ??
And where you included the above code ??


#3

Yes, It is a script report. I have included it in my script report’s js file.


#4

Could you share screenshot or code of JS ?


#5

v11 frappe uses datatable (changed from slickgrid) and the signature for formatter has changed to below.

"formatter": function (value, row, column, data, default_formatter) {

Change your code accordingly


#6

@vijaywm @apkrajar
I also have the same error
Uncaught (in promise) TypeError: default_formatter is not a function

my js file is

frappe.query_reports['All Full Funnel'] = {

  "formatter": function (value, row, cell, column, data, default_formatter) {
    value = default_formatter(row, cell, value, column, data);
    if (data.Stage < 90) {
      value = `<span style='color:red!important;font-weight:bold'>${value}</span>`;
    }
    if (data.Stage == 90) {
      value = `<span style='color:blue!important;font-weight:bold'>${value}</span>`;
    }
    if (data.Stage > 90) {
      value = `<span style='color:green!important;font-weight:bold'>${value}</span>`;
    }
    return value;
  },
};

#7

@raghav
did you fix the error


#8

@Alaa_Badri please make the below change and try

"formatter": function (value, row, cell, column, data, default_formatter) {

to

"formatter": function (value, row, column, data, default_formatter) {

#9

@vijaywm thanks for your reply but i got the same error

VM837:13 Uncaught (in promise) TypeError: default_formatter is not a function
    at Object.formatter (<anonymous>:13:13)
    at format (query_report.js:662)
    at ft.getCellContent (frappe-datatable.cjs.js:3323)
    at ft.getCellHTML (frappe-datatable.cjs.js:3287)
    at frappe-datatable.cjs.js:4093
    at Array.map (<anonymous>)
    at mt.getRowHTML (frappe-datatable.cjs.js:4093)
    at Object.generate (frappe-datatable.cjs.js:4584)
    at e.value (frappe-datatable.cjs.js:4353)
    at e.value (frappe-datatable.cjs.js:4436)

#10

can you do just inside the formatter function and share output

 "formatter": function (value, row, cell, column, data, default_formatter) {
    console.log(row, cell, value, column, data);

    value = default_formatter(row, cell, value, column, data);
   

#11

Could you solve it?

Try the following code:

“formatter”: function(value, row, column, data, default_formatter) {
value = default_formatter(value, row, column, data);
Insert your formatting code
return value

Source:
Github ERPNext