0

I'm using JqGrid with MVCJqGrid Html wrapper in my mvc5 project. MVCJqGrid version I'm using is 1.0.15. I have following code in my cshtml file in order to create grid in page.

@(Html.Grid("Contacts")
        .SetCaption("Contacts")
        .SetUrl(@Url.Action("Contacts", "Home"))
        .SetAutoWidth(true)
        .SetViewRecords(true)
        .AddColumn(new Column("Name").SetAlign(Align.Left).SetEditable(false))
        .AddColumn(new Column("IsPrimaryContact").SetAlign(Align.Center).SetFormatter(Formatters.Checkbox).SetLabel("Is Primary?"))
        .AddColumn(new Column("Email").SetLabel("Email Address").SetFormatter(Formatters.Email))
        .AddColumn(new Column("Handphone").SetAlign(Align.Right).SetFormatter(Formatters.Number))
        .AddColumn(new Column("Office").SetAlign(Align.Right))
        .AddColumn(new Column("Telephone").SetAlign(Align.Right))
        .AddColumn(new Column("Other").SetAlign(Align.Right))
)

In above code, "IsPrimaryContact" is bool value and I display it as checkbox column in grid. When page loads, all the columns are shown as readonly i.e. I cannot edit but Checkbox column remains editable and can check/uncheck the checkbox in column. I want checkbox also to be disabled and user should not be able to change its value. I have already added SetEditable for Checkbox column to false and also tried few other things but checkbox in column always remains enabled. How I can show the checkboxes in column as disabled when page loads?

user2185592
  • 368
  • 1
  • 8
  • 24

1 Answers1

0

Instead of using the standard formatters, you could use a custom formatter. You can find an example here http://mvcjqgrid.skaele.it/Home/Formatters

Set the custom formatter for the column:

.AddColumn(new Column("IsPrimaryContact").SetAlign(Align.Center).SetCustomFormatter("displayCheckBox").SetLabel("Is Primary?"))

Formatter function

<script type="text/javascript">
    function displayCheckBox(cellvalue, options, rowobject) {
        return '<input type="checkbox" value="' + cellvalue + '" disabled="disabled">';
    }
</script>

Didn't test the code, but it should work ;)

Robin van der Knaap
  • 4,060
  • 2
  • 33
  • 48
  • Thanks Robin for your answer. I'm new to JqGrid and this answer of yours taught me the use of CustomFormatter. I had one more question but not related to this problem. If I want to provide binding for the data instead of getting data from controller method is it possible? I use [KMVC](https://www.nuget.org/packages/kMVC/). – user2185592 Dec 09 '14 at 16:34
  • If I understand your question correctly, you mean databinding like in asp.net webforms? If so, no, that's not possible as far as I know. – Robin van der Knaap Dec 10 '14 at 09:29