数据不在jqgrid中显示?

时间:2013-12-12 12:49:43

标签: jquery jqgrid

我正在使用jqgrid,我发现了一个奇怪的问题,问题是单元格中的数据没有显示,当我使用mozilla firefox的开发工具时,通过检查单元格我发现了这个:

<tr id="JobObservation-1" class="ui-widget-content jqgrow ui-row-ltr ui-state-highlight" tabindex="0" role="row" aria-selected="true">
<td aria-describedby="Observations_Id" title="JobObservation-1" style="display:none;" role="gridcell">JobObservation-1</td>
<td aria-describedby="Observations_Observations" title="" style="text-align:left;" role="gridcell"> </td>
<td class="not-editable-cell" aria-describedby="Observations_Delete" title="" style="text-align:center;" role="gridcell">
</tr>

在第一个td中,您可以看到值“JobObservation-1”及其隐藏,并且在第二个td中没有值。我不知道我错过了什么,但网格显示的单元格只是空白,

这是我的网格JS代码:

 jQuery(document).ready(function () {

        debugger;
        var grid = jQuery("#Observations");

        grid.jqGrid({
            url: '/Admin/GetObservationsSummer',
            datatype: 'json',
                mtype: 'Post',
               cellsubmit: 'remote',
               cellurl: '/Admin/SaveObservationSum',
               height: '100%',
               pager: '#sumobspgr',

               colNames: ['Id', 'Observations', ''],
            colModel: [
            { name: 'Id', index: 'Id', key: true, hidden: true, editrules: { edithidden: true } },
            //{ name: 'Observations', index: 'NoteName', align: "center", sorttype: 'text', resizable: true, editable: true },
             { name: 'Observations', index: 'NoteName', width: 100, align: "left", sorttype: 'text', resizable: true, editable: true, editrules: { required: true } },

            { name: 'Delete', index: 'Delete', width: 25, resizable: false, align: 'center', classes: 'not-editable-cell' }

            ],    



            width: '680',
            caption: 'Summer Observations',
            hidegrid: false,
            del: true,
            cellEdit: true,
            viewrecords: true,

            gridComplete: function () {

                var ids = grid.jqGrid('getDataIDs');
                for (var i = 0; i < ids.length; i++) {
                    var isDeleted = grid.jqGrid('getCell', ids[i], 'Delete');
                    if (isDeleted != 'true') {
                        grid.jqGrid('setCell', ids[i], 'Delete', '<a href="#" onclick="deleteSumNote(' + ids[i] + ');"><img src="/Images/delete.png" alt="Delete Row" /></a>');
                    }
                    else {
                        grid.jqGrid('setCell', ids[i], 'Delete', ' ');
                        //grid.jqGrid('setCell', ids[i], 'Privileges', 'admin');
                    }
                }
            }
        }

        );

        grid.jqGrid('navGrid', '#sumobspgr',
       { resize: false, add: false,search:false, del: false, refresh: false, edit: false, alerttext: 'Please select one user' }

   ).jqGrid('navButtonAdd', '#sumobspgr',
       { title: "Add New Note", buttonicon: "ui-icon ui-icon-plus", onClickButton: showNewSONModal, position: "First", caption: "" });

    });

    function showNewSONModal() {

        var grid = jQuery("#Observations");
        $("#form_Sumerobs").dialog(
                {
                    open: function (event, ui) {

                        $("#txtsumNote").val('');
                        $("#trFormerrorSumObs").hide();
                        $("#trFormerrorSumObs td").text('');

                    },
                    buttons: {
                        "Submit": function () {
                            debugger;
                            if (ValidateTruck() == true) {
                                $('#error').ajaxError(function (event, request, settings) {
                                    $('#waitingSumobsr').hide();
                                    $(this).addClass('errordiv').text(request.statusText + "" + request.status);

                                });
                                $.post('/Admin/form_Sumerobs/',
                                $('#form_Sumerobs').serialize(),
                                function (data) {
                                    debugger;
                                    if (data == 'Success') {
                                        $('#form_Sumerobs').dialog("close");
                                        grid.jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
                                    }
                                    else {
                                        $("#trFormerrorSumObs").show();
                                        $("#trFormerrorSumObs td").text(data);
                                    }

                                });
                            }
                        },
                        "Cancel": function () {
                            $('#error').removeClass("errordiv").text("");
                            $('#waiting').hide();
                            $(this).dialog("close");
                        }
                    },
                    modal: true,
                    title: "New Note",
                    minWidth: 400,
                    resizable: false
                }
        ).dialog('open');
    }

    function ValidateTruck() {
            var flag = true;
            var errorMSG = '';
            $("#trFormerrorSumObs td").text('');
            if ($("#txtsumNote").val() == '') {
                errorMSG += 'Note cannot be blank';
                flag = false;
            }


            if (flag == false) {
                $("#trFormerrorSumObs").show();
                $("#trFormerrorSumObs td").text(errorMSG);
            }
            else {
                $("#trFormerrorSumObs td").text('');
                $("#trFormerrorSumObs").hide();
            }
            return flag;
        }

    function deleteSumNote(rowid) {
        debugger;
        jQuery('#Observations').delGridRow(rowid, {
            url: '/Admin/DeleteSumNote', caption: 'Delete Note?', msg: 'Delete selected Note? <br />Careful, this is irreversable!',
            afterSubmit: function (serverStatus, postdata) {

                var response = serverStatus.responseText;
                var rst = 'false';
                debugger;
                if (response == rst) {
                    debugger;

                    return [false, "Note in use"];

                }
                else {

                    return [true, ""];

                }
            },
        });

        }

来自控制器的cs代码在这里:

public ActionResult GetObservationsSummer(GridSettings grid)
        {
            List<Observation> lst = new List<Observation>();
            using (DataContext db = new DataContext())
            {
              lst= db.Observation.ToList();
            }

            if (grid.IsSearch)
            {
                //lst.RemoveAll(e => !CheckRule(grid.Where, e));
            }

            int total = lst.Count();
            //DateTime dateTime;
            var jsonData = new
            {
                total = (int)Math.Ceiling((double)total / grid.PageSize),
                page = grid.PageIndex,
                records = total,
                rows = (
                    from obj in lst
                    select new
                    {
                        //['Id', 'Privileges', 'First Name', 'Last Name', 'User Name', 'Password', 'Password Expiry', 'Type','Last Modified', 'Last Modified By', 'Created By',''],
                        i = obj.NoteId,
                        cell = new string[] {                                       

                            obj.NoteName
                        }

                    }

                ).ToArray()
            };
            // jsonData.rows
            //r.Data = jsonData;

            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }

和html是这样的:

 <div class="right-pannel summer_observations">
            <div class="inner-bcum">On Site Logs<span class="seprator"></span>Summer Observations</div>
            <div class="inner-box-area">
                <div class="display-div display-div-2 flat-margin">
                    <table id="Observations">

                </table>
                </div>

                <div id="sumobspgr"></div>
                 <form id="form_Sumerobs" class="ui-widget ui-widget-content ui-corner-all ui-jqdialog jqmID1">
                            <div id="divSumerobs" style="width: 350px">
                                <div class="ui-jqdialog-content ui-widget-content">                                    
                                    <table class="EditTable" cellspacing="0" cellpadding="0" border="0">
                                        <tr>
                                            <td>
                                                <div id="waitingSumobsr" class="waiting ui-state-default ui-state-active" style="display:none">
                                                 Waiting.....
                                                </div>
                                            </td>
                                        </tr>
                                        <tr id="trFormerrorSumObs">
                                            <td colspan="2" class="ui-state-error"></td>
                                        </tr>
                                        <tr>
                                            <td class="CaptionTD">
                                                Note
                                            </td>
                                            <td class="DataTD">
                                                <input type="text" name="txtsumNote" id="txtsumNote" size="60" class="FormElement ui-widget-content ui-corner-all" />
                                            </td>
                                        </tr>

                                    </table>
                                </div>
                            </div>
                        </form>
                <div class="clear"></div>
            </div>
        </div>

我不知道我错过了什么。任何帮助将不胜感激。如果它对我有用,我一定会给你答案。提前致谢

1 个答案:

答案 0 :(得分:0)

我在控制器cs代码中犯了一个错误

我这样做了:

 public ActionResult GetObservationsSummer(GridSettings grid)
        {
            List<Observation> lst = new List<Observation>();
            using (DataContext db = new DataContext())
            {
              lst= db.Observation.ToList();
            }

            if (grid.IsSearch)
            {
                //lst.RemoveAll(e => !CheckRule(grid.Where, e));
            }

            int total = lst.Count();
            //DateTime dateTime;
            var jsonData = new
            {
                total = (int)Math.Ceiling((double)total / grid.PageSize),
                page = grid.PageIndex,
                records = total,
                rows = (
                    from obj in lst
                    select new
                    {

                        i = obj.NoteId,
                        cell = new string[] {   
                            obj.NoteId.ToString(),
                            obj.NoteName,
                        }

                    }

                ).ToArray()
            };

查看代码

 select new
                        {

                            i = obj.NoteId,
                            cell = new string[] {   
                                obj.NoteId.ToString(),
                                obj.NoteName,
                            }

                        }

问题解决了;)