Search code examples
model-view-controllercheckboxgridmvcjqgrid

JqGrid MVC Razor checkbox column to select rows


I have this grid in my MVC app. I want to add a column at the beginning, that allows the user to select rows and then on the POST method I will get the info of the rows selected. Also I want to add a main checkbox in the header that allows to select all checkboxes(rows) on the table.

This is what I have:

@(Html.Grid("basic")
    .SetRequestType(RequestType.Post)
    .SetJsonReader(new MvcJqGrid.DataReaders.JsonReader { Id="ID", RepeatItems = false})
    .SetCaption("Teams")
                .AddColumn(new Column("<input type=checkbox editable=true>").SetFormatter(Formatters.Checkbox)
        .SetEditable(true)
        .SetWidth(32)
        .SetFixedWidth(true)
        .SetSortable(false)
            .SetAlign(Align.Right))
    .AddColumn(new Column("Identifier")
        .SetLabel("Team Code")
        .SetWidth(80))
    .AddColumn(new Column("ClientName")
        .SetWidth(135)
        .SetLabel(Html.DisplayColumnNameFor(Model, m => m.Client.ClientName, typeof(Client)).ToHtmlString()))
    .AddColumn(new Column("Name")
        .SetWidth(135))
    .AddColumn(new Column("IsActive")
        .SetWidth(60)
        .SetFixedWidth(true)
        .SetLabel("Active")
        .SetAlign(Align.Center)
        .SetDefaultSearchValue("Active")
        .SetSearchType(Searchtype.Select)
        .SetSearchTerms(new string[] { "Active", "Deactivated", })
        .SetFormatter(Formatters.Checkbox))
    .SetUrl(Url.Action("Search", "CaseTeam"))
    .SetAutoWidth(true)
    .SetWidth(933)
    .SetRowNum(20)
    .SetRowList(new int[]{10,15,20,50})
    .SetViewRecords(true)
    .SetPager("pager")
    .SetSearchToolbar(true).SetSearchOnEnter(false)
    .SetSortName("Identifier") )

What I see is all the checkboxes I want but:

  • The header checkbox can be clicked but it wont be checked.
  • The rest of the checkboxes cant be clicked. (I have editable to true)

I dont know whats going on, any ideas?


Solution

  • Solved it adding

    .SetMultiSelect(true)
    

    My error was trying to add the column for that, when there is an attribute that does that already.