Javascript 动态数据到Jqgrid

Javascript 动态数据到Jqgrid,javascript,jquery,ajax,jqgrid,Javascript,Jquery,Ajax,Jqgrid,我正在使用jqgrid来列出数据。现在每当我单击搜索按钮时,我都想动态地将来自使用ajax的控制器操作的数据分配给jqgrid。但是数据仍然是第一次加载。有什么想法吗 $('#listatt').jqGrid({ datatype: 'local', viewrecords: true, sortname: 'RowNumber', sortorder: 'desc', cellsubmit: 'clien

我正在使用jqgrid来列出数据。现在每当我单击搜索按钮时,我都想动态地将来自使用ajax的控制器操作的数据分配给jqgrid。但是数据仍然是第一次加载。有什么想法吗

    $('#listatt').jqGrid({
        datatype: 'local',

        viewrecords: true,
        sortname: 'RowNumber',
        sortorder: 'desc',
        cellsubmit: 'clientArray',
        editurl: 'clientArray',
        cellEdit: true,

        data: mydata,

        colNames: ['Sl.#', 'id', 'empid', 'Name', 'Code', 'Time', 'Status', 'Type', 'Reason'],
        //columns model
        colModel: [
                        { name: 'RowNumber', index: 'RowNumber', align: 'left', editable: true, edittype: 'text', width: '35px' },
                         { name: 'sl_No', index: 'sl_No', align: 'left', search: false, stype: 'text', searchoptions: { sopt: ['eq'] }, width: '10px', hidden: true },
                             { name: 'emp_ID', index: 'emp_ID', align: 'left', editable: true, edittype: 'text', width: '35px', hidden: true },


                        { name: 'emp_Name', index: 'emp_Name', align: 'left', search: false, stype: 'text', editable: false, searchoptions: { sopt: ['eq'] }, width: '200px' },
                        { name: 'emp_Code', index: 'emp_Code', align: 'left', search: false, stype: 'text', editable: false, searchoptions: { sopt: ['eq'] }, width: '250px' },
                        { name: 'attTime', index: 'attTime', template: dateTemplate
                        },

                        { name: 'inOut', index: 'inOut', width: 100, editable: true, edittype: 'select', editoptions: { value: "0:Select;1:In;2:Out" }, hidden: true },
                               { name: 'attType_ID', index: 'attType_ID', width: 100, formatter: "select", editable: true, edittype: 'select', editoptions: { value: "0:Absent;1:Present;2:Half Day"} },
                     { name: 'attReasons', index: 'attReasons', width: 200, sortable: false, editable: true, edittype: "textarea", editoptions: { rows: "2", cols: "10"} }


                      ],

        //pager for grid
        pager: $('#pager'),
        //number of rows per page
        rowNum: 20,
        rowList: [10, 20, 40, 80, 100],
        viewrecords: true,
        //grid height
        height: '380px',
        height: '500px',
        shrinkToFit: true

    });
--ajax调用

        $.ajax({
            url: '@Url.Action("GetGridDataSequence")',
            data: { branchID: $("#branchID").val(), divisionID: $("#divisionID").val(), shiftID: $("#shiftID").val(), chkout: $("#chkout").is(':checked'), attdate: $("#attdate").val() },
            dataType: "json",
            type: "POST",
            error: function () {
                alert("An error occurred.");
            },
            success: function (data) {



                $('#listatt').jqGrid('setGridParam',
          {
              datatype: 'local',
              data: data
          })
.trigger("reloadGrid");

            }
        });
--控制器

public string  GetGridDataSequence(int branchID, int divisionID, int shiftID, Boolean chkout,DateTime attdate)
        {
            Attendence Attendence = new Attendence();
            AttendenceInfo AttendenceInfo = new AttendenceInfo();
            var dt = Attendence.AttendenceSelectAll(Convert.ToInt32(this.Session["CompanyID"]), branchID, divisionID, shiftID, attdate, chkout);
            var jason = JsonConvert.SerializeObject(dt);
            return jason;

        }

我认为您需要将网格的数据类型从“local”更改为“json”,并添加属性“url” 在我的项目中(例如):


你可以试试这样的

function loadGrid(data){
  $('#listatt').jqGrid({
    datatype: 'local',
    data: data,
    ....
  });
}
在ajax成功函数中

success: function (data) {
     $("#listatt").jqGrid('GridUnload');
     loadGrid(data);
}
success: function (data) {
     $("#listatt").jqGrid('GridUnload');
     loadGrid(data);
}