0

VS2010 を使用して ASP.NET MVC アプリケーションで JqGrid を使用しています。私のグリッドはビューで適切にレンダリングされないようで、ビューの他のコントロール (ページ全体を含む) にアクセスできません。画面のブローを参照してください。

行を含むグリッド:

ここに画像の説明を入力 行のないグリッド: ここに画像の説明を入力

しかし、データを変更してコントローラーのインライン編集に戻すと、入力ページにアクセスできるようになります。

私のスクリプト:

        var last_selected_row;
        $(function () {

        var outerwidth = $('#studentList').width() - 10; ////Keep Grid 10 pixel smaller than its parent container

        $('#studentGrid').jqGrid({
        // Ajax related configurations

        //url to send request to
        url: "/Registration/LoadStudents",
        datatype: "json",
        mtype: "POST",
        // Specify the column names
        colNames: ["StudentID", "StudentName", "Status", "Grades", "StartDate", "EndDate", "EarnedDate", "DroppedDate"],

        // Configure the columns
        colModel: [
        { name: "StudentID", index: "StudentID", width: 0, align: "left", key: true },
        { name: "StudentName", index: "StudentName", editrules: { required: true, integer: false }, width: 100, title: "Name", align: "left", editable: true, stype: 'text', sortable: true },
        { name: "Status", index: "Status", width: 70, align: "left", editable: true, edittype: "checkbox", editoptions: { value: "true:false"} },
        { name: "Grades", index: "Grades", width: 80, align: "left", editable: true, edittype: "select", editoptions:
        {
        dataUrl: "/Registration/GetAllGrades",
        buildSelect: function (data) {
        //var d = $.parseJSON(data);
        var jqGridAssemblyTypes = $.parseJSON(data);
        var s = '<select>';
        if (jqGridAssemblyTypes && jqGridAssemblyTypes.length) {
        for (var i = 0, l = jqGridAssemblyTypes.length; i < l; i++) {
        var ri = jqGridAssemblyTypes[i];
        s += '<option value="' + ri.Value + '">' + ri.Text + '</option>';
        }
        }
        return s + "</select>";
        },
        dataInit: function (elem) {
        var v = $(elem).val();
        ////Set other column value here
        },
        dataEvents: [{
        type: 'change',
        fn: function (e) {
        var assemblyType = $(e.target).val();
        //var rowId = getRowId($(this));
        }
        }]
        }
        },
        { name: "StartDate", editable: true, editrules: { edithidden: false }, editoptions: { dataInit: function (element) { SetFieldReadOnly(element); } }
        , index: "StartDate", width: 100, align: "left", formatter: 'date', formatoptions: { srcformat: 'm/d/Y', newformat: 'm/d/Y' }
        },
        { name: "EndDate", editable: true, editrules: { edithidden: false }, editoptions:
        { dataInit: function (element) {
        $(element).attr("readonly", "readonly");
        }
        }, index: "EndDate", title: "Ended", width: 100, align: "left", formatter: 'date', formatoptions: { srcformat: 'm/d/Y', newformat: 'm/d/Y' }
        },
        { name: "EarnedDate", editable: true, editrules: { edithidden: false }, editoptions:
        { dataInit: function (element) {
        $(element).attr("readonly", "readonly");
        }
        }, index: "EarnedDate", title: "Earned", width: 100, align: "left", formatter: 'date', formatoptions: { srcformat: 'm/d/Y', newformat: 'm/d/Y' }
        },
        { name: "DroppedDate", editable: true, editrules: { edithidden: false }, editoptions:
        { dataInit: function (element) {
        $(element).attr("readonly", "readonly");
        }
        }, index: "DroppedDate", title: "Dropped", width: 100, align: "left", formatter: 'date', formatoptions: { srcformat: 'm/d/Y', newformat: 'm/d/Y' }
        }],

        // Grid total width and height
        //width: 300,
        //height: 200,
        //autowidth: true,
        height: '100%',
        altRows: true,
        shrinkToFit: false,
        //forceFit: true,
        gridview: true,
        //width: 600,

        // Paging
        toppager: false,
        pager: $("#studentGridPager"),
        rowNum: 5,
        rowList: [5, 10, 20],
        viewrecords: true,

        // Default sorting
        sortname: "StudentID",
        sortorder: "asc",

        ajaxRowOptions: { contentType: "application/json", dataType: "json" },
        serializeRowData: function (data) {
        return JSON.stringify({ registrationModel: data });
        },
        ondblClickRow: function (StudentId) { StudentDoubleClicked(StudentId); },

        // Grid caption
        editurl: "/Registration/EditStudents",
        jsonReader: { repeatitems: false },
        caption: "Students"

        }).setGridWidth(outerwidth);

        function bindAllGrades() {
        var dataString = '';
        var grades = new Array();
        $.getJSON("/Registration/GetAllGrades", null, function (data) {
        if (data != null) {
        $.each(data, function (i, item) {

        grades.push("{\"Text\":\"" + item.Text + "\",\"Value\":\"" + item.Value + "\"}");
        dataString += "{\"Text\":\"" + item.Text + "\",\"Value\":\"" + item.Value + "\"},";
        });
        dataString = dataString.slice(0, -1);

        }

        });

        var jstrin = JSON.stringify(grades);
        return grades;

        }

        function StudentDoubleClicked(StudentId) {
        var $myGrid = $("#studentGrid");
        if (StudentId && StudentId != last_selected_row) {
        $myGrid.jqGrid('restoreRow', last_selected_row);


        $myGrid.jqGrid('saveRow', StudentId, {
        successfunc: function (response) {
        alert('Row is Saved !!!');
        return true;
        }
        }, '/Registration/EditStudents',
        {
        extraparam: {
        StudentID: function () {

        var sel_id = $myGrid.jqGrid('getGridParam', 'selrow');
        var value = $myGrid.jqGrid('getCell', sel_id, 'StudentID');
        return stId;
        },
        StudentName: getSavedMathValue(StudentId),
        Status: function () {
        var sel_id = $myGrid.jqGrid('getGridParam', 'selrow');
        var value = $myGrid.jqGrid('getCell', sel_id, 'Status');
        return value;
        }
        }
        }, function () { alert('This is After save.') }, function () { alert('Error while saving data.') }, reload);
        $myGrid.jqGrid('editRow', StudentId, true);

        last_selected_row = StudentId;
        }

        }

        function getSavedMathValue(stId) {
        var mval = $('#' + stId + "_StudentName");
        return mval.val();
        }

        function SetFieldReadOnly(Ele) {
        $(Ele).attr("readonly", "readonly");
        }
        })
        function reload(rowid, result) {
        alert("This is Reload " + Result);
        $("#studentGrid").trigger("reloadGrid");
        }

私の見解:

        <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<SISShsmMvc.Models.RegistrationModel>" %>

        <!DOCTYPE html>
        <html>
        <head runat="server">
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <script type="text/javascript" src="../../Scripts/jquery.jqGrid.js"></script>
        <script type="text/javascript" src="../../Scripts/jquery.jqGrid.locale-en.js"></script>
        <%: Scripts.Render("~/bundles/autocomplete")%>

        <script type="text/javascript" src="../../Scripts/Registration.js"></script>
        </head>
        <body>

        <div>
        <fieldset>
        <legend>Search Student By</legend>
        <div id="studentSearch">
        <span>Name:</span><br />
        <%= Html.TextBoxFor(m => m.StudentName, new { ID = "StudentName" })%><br />
        <span>Grade:</span><br />
        <%= Html.DropDownListFor(m => m.SelectedGrade, Model.AvailableGrades) %><br />
        </div>
        </fieldset>
        <div id="studentList">
        <table id="studentGrid">
        </table>
        <div id="studentGridPager" />
        </div>
        </div>
        </body>
        </html>

私のコントローラー:

            public ActionResult Index()
            {
            PopulateUserContextViewBags();

            List<string> grades = new List<string>();
            grades.Add("Grades 11 and 12");
            grades.Add("Grades 12");
            grades.Add("Grades 11");
            grades.Add("Grades 10");
            grades.Add("All Grades");

            // TODO: 
            Models.RegistrationModel model = new Models.RegistrationModel()
            {
            AvailableGrades = new SelectList(grades, "Grades 11 and 12")
            };

            return View(model);
            }

            public ActionResult LoadStudents()
            {
            var objmodel = Models.RegistrationRepository.GetStudents();
            return Json(objmodel, JsonRequestBehavior.AllowGet);
            //return Json(null, JsonRequestBehavior.AllowGet);
            }

            public JsonResult EditStudents(Models.RegistrationModel registrationModel)
            {
            // registrationModel.StudentID = id;

            return Json(null, JsonRequestBehavior.AllowGet);
            }

JqG​​rid 4.5.1 を使用しています。このコードを IE9 と Firefox 22.0 でテストしました。何か助けて??

4

1 に答える 1