Search code examples
jqueryasp.net-mvcjqgridlib.web.mvc

Lib.Web.Mvc.JQuery.JqGrid Add/Edit buttons not appearing


I have the excellent library Lib.Web.Mvc.JQuery.JqGrid from NuGet working except for the feature that adds Add/Edit buttons. I am using the following code to initialize the table:

@{
    var grid = new JqGridHelper<TVTViewModel>("tuples",
        dataType: JqGridDataTypes.Json,
        methodType: JqGridMethodTypes.Post,
        pager: true,
        rowsNumber: 50,
        sortingName: "RecordId",
        sortingOrder: JqGridSortingOrders.Asc,
        url: Url.Action("Details", new { nctId = Model.NctId }),
        viewRecords: true,
        cellEditingEnabled: true,
        cellEditingSubmitMode: JqGridCellEditingSubmitModes.ClientArray
        )
        .AddActionsColumn("Actions", width: 25,
inlineEditingOptions: new JqGridInlineNavigatorActionOptions { Keys = true },
editButton: false,
deleteOptions: new JqGridNavigatorDeleteActionOptions { Url = Url.Action("Test", "Test") });
}

and the following controller response code:

        JqGridResponse response = new JqGridResponse()
        {
            TotalPagesCount = (int)Math.Ceiling((float)totalRecordsCount / (float)request.RecordsCount),
            PageIndex = request.PageIndex,
            TotalRecordsCount = totalRecordsCount
        };

        int i = 0;

        foreach (TVTViewModel v in viewModels)
        {
            v.RecordId = i;
            response.Records.Add(new JqGridRecord<TVTViewModel>(v.RecordId.ToString(), v));
            i++;
        }

        return new JqGridJsonResult() { Data = response };

but when the page renders, the additional column just shows up as "undefined" for every row in the column.

Online it was suggested in several places to make sure that the response had the response.Reader.RepeatItems = false; which I have tried (and it didn't work). Any other suggestions?


Solution

  • Yeah, so it was something stupid.

    I need to include grid.locale-en.js which is typically in the scripts/i18n folder if you get it from NuGet.

    See jqgrid undefined integer? pager not loading for more details on similar issues.