How to set jqGrid "editoption" with Lib.Web.MVC

197 Views Asked by At

I have a bool data value (true / false) that I want to display as Yes / No in the jqGrid cell.

How do I annotate the view model property to do this?

I think the code below may work but I do not know how to add edit options to the property annoation.

editoptions: { value: "false:No;true:Yes" }
1

There are 1 best solutions below

0
tpeczek On BEST ANSWER

Lib.Web.Mvc supports two ways of providing values for select edit/search fields:

  1. Remote - requires a controller action which will return the values via AJAX call (sample can be find in demo project).
  2. Dedicated class - requires creating a class with specific method.

The second way might work in your case. First you need a class to provide your values:

public class YesNoEditOptionsProvider
{
    private static readonly IDictionary<string, string> _editOptions = new Dictionary<string, string>() {
        { "false", "No" },
        { "true", "Yes" }
    };

    public IDicitionary<string, string> GetEditOptions()
    {
        return _editOptions;
    }
}

Now you can apply this class to your propery:

[JqGridColumnEditable(true, typeof(YesNoEditOptionsProvider), "GetEditOptions", EditType = JqGridColumnEditTypes.Select)]
public bool YesNoColumn { get; set; }