1

I'm attempting to use the ASP.Net MVC version of jqGrid to display a simple data grid. One of the columns in my grid is an Enum and jqGrid is displaying is as an int whereas I want to display it as a string. How can I get jqGrid to display it as a string?

new JQGridColumn { DataField = "ApprovalStatus", 
     DataType = typeof(ApplicationStatusTypes),
     Editable = false,
     Width = 200},

public enum ApplicationStatusTypes
{
    Unassessed = 0,
    AssessmentInProgress = 1,
    RequirementsNotMet = 2,
    RequirementsPartiallyMet = 3,
    RequirementsMet = 4,
    Approved = 5
}

When the jqGrid is rendered the ApprovalStatus column shows up as an int instead of a string. I've tried messing around with DataFormatString on the column but to no avail.

1 Answer 1

2

I see that this is an old question, but for any lost soul, that will come here.

First step is to set a SetFormatter(Formatters.Select) for the column used for displaying an enum.

But then you need to provide a list of enum mappings. jqGrid expects them to be provided as a string in format of enumValue1:enumName1;enumValue2:enumName2 directly to .SetEditOptions(new EditOptions { Value = ... }) - unfortunately the API naming convention is broken here.

The string generation itself is pretty straightforward and can be generalized to the following expression:

string.Join(";", Enum.GetNames(typeof(T)).Zip(Enum.GetValues(typeof(T)).Cast<int>(), (text, val) => val.ToString() + ":" + text));

, where T is generic parameter being an enum type.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.