Lib.Web.Mvc with edittype select and multiple true

600 Views Asked by At

After read this post of a custom implementation of DataEvents on Lib.Web.Mvc. I need to create a column of type ListBox, something like

[Required]
[Display(Name = "Actions")]
[JqGridColumnEditable(true, "Actions", "Home", EditType = JqGridColumnEditTypes.Select)]
[JqGridColumnEditOptions.Multiple=true]
public string Actions { get; set; }

Can anyone help me or give me a reference. I really do not know how to do this.

1

There are 1 best solutions below

5
On BEST ANSWER

You can subclass JqGridColumnEditableAttribute and add Multiple property through HtmlAttributes collection:

public class JqGridColumnMultipleEditableAttribute : JqGridColumnEditableAttribute
{
    public bool Multiple { get; set; }

    protected override IDictionary<string, object> HtmlAttributes
    {
        get
        {
            if (Multiple)
                return new Dictionary<string, object>() { { "multiple", "multiple" } };
            else
                return null;
        }
    }

    public JqGridColumnMultipleEditableAttribute(bool editable)
        : base(editable)
    {
        Multiple = false;
    }

    public JqGridColumnMultipleEditableAttribute(bool editable, string dataUrlRouteName)
        : base(editable, dataUrlRouteName)
    {
        Multiple = false;
    }

    public JqGridColumnMultipleEditableAttribute(bool editable, string dataUrlAction, string dataUrlController) :
        this(editable, dataUrlAction, dataUrlController, null)
    { }

    public JqGridColumnMultipleEditableAttribute(bool editable, string dataUrlAction, string dataUrlController, string dataUrlAreaName)
        : base(editable, dataUrlAction, dataUrlController, dataUrlAreaName)
    {
        Multiple = false;
    }
}

You can use attribute created in this way like this:

[Required]    
[Display(Name = "Actions")]    
[JqGridColumnMultipleEditable(true, "Actions", "Home", EditType = JqGridColumnEditTypes.Select, Multiple=true)]      
public string Actions { get; set; }

This will cause jqGrid to render ListBox (you might need to do some styling to make it look good).