Show Enum description in Jqgrid instead of Enum

I have an Enum, as it is written in Java:

public enum Status
{
  ACTIVE("Active"), IN_ACTIVE("InActive");

  Status(String desc)
  {
    this.description = desc;
  }

  private String description;

  public String getDescription()
  {
    return description;
  }

  public void setDescription(String desc)
  {
    this.description = desc;
  }
}

This listing is a property in jqGrid. But it always displays an enumeration, i.e. ACTIVE or IN_ACTIVE. I want jqgrid to show Active and InActive. Thanks

+5
source share
2 answers

You can write a custom formatter to achieve this. For instance:

formatStatus: function (cellvalue, options, rowObject){
   if (cellvalue == "ACTIVE")
       return "Active";
   return "InActive";
}

Then make sure you use the formatter from your colmodel:

{name: 'status', formatter: formatStatus, ...},

Does it help?

+2
source

You have toString () implemented in your Enum as follows

public toString() {
    return description;
}

This will make sure your json response has a description instead of the name Enum.

+1
source

All Articles