jqgrid:如何在记录插入后重新加载网格?

时间:2011-04-06 18:22:51

标签: javascript jquery jqgrid

我使用jqGrid显示从数据库表中检索的数据。我正在使用jqGrid的Add对话框来添加新记录。添加记录后,我一直无法强制网格从数据库重新加载。经过多次搜索并尝试在这里和其他地方找到各种解决方案。我找到了一种让它发挥作用的方法。我想。我的重新加载在Firefox中运行良好,但在Internet Explorer中完全没有。有没有人对为什么或建议有任何想法?

以下代码:

function reloadLOIs() {
 if (reloadLOIGrid) {
    $("#LOIEdit").trigger("reloadGrid");
    reloadLOIGrid = false;
 }
}

function getLOIs() {
var tid = document.getElementById("LOITopicFilter").value;
var sid = document.getElementById("LOISubTopicFilter").value;

if (tid == "" || sid == "") {
    return false;
}

$.ajax({
    url: "Restful.svc/GetLOIs",
    data: { topicID: tid, subtopicID: sid },
    dataType: "json",
    type: "GET",
    contentType: "application/json; charset=utf-8",
    success: function (data, status, xHR) {
        var thegrid = jQuery("#LOIEdit")[0];
        thegrid.addJSONData(JSON.parse(data.d));
        $("#LOIEdit").fluidGrid({ example: "#outerContainer3", offset: -10 });
    },
    complete: function (xHR, status) {
        return true;
    },
    error: function (xHR, status, err) {
        alert("ERROR: " + status + ", " + err);
    }
});
}



function LoadLOIDataIntoGrid() {

var lastsel;
var tid = document.getElementById("LOITopicFilter").value;
var sid = document.getElementById("LOISubTopicFilter").value;


document.getElementById('ctl00_Body_hidTopicFilter').value = tid;
document.getElementById('ctl00_Body_hidSubtopicFilter').value = sid;


jQuery("#LOIEdit").jqGrid({
    datatype: getLOIs,
    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
    height: '300px',
    colNames: ['TopicID', 'SubTopicID', 'LOIID', 'LOI Number', 'Description', 'Reference', 'Inactive'],
    colModel: [
                    { name: 'TopicID', index: 'TopicID', hidden: true, width: 60, editable: true, editrules: { edithidden: false }, editoptions: { size: 10, defaultValue: tid} },
                    { name: 'SubTopicID', index: 'SubTopicID', hidden: true, width: 60, editable: true, editrules: { edithidden: false }, editoptions: { size: 10, defaultValue: sid} },
                    { name: 'LOIID', index: 'LOIID', hidden: true, width: 60, editable: true, key: true, editrules: { edithidden: false }, editoptions: { size: 10} },
                    { name: 'LOIOrderNumber', index: 'LOIOrderNumber', width: 40, editable: false, editoptions: { size: 30} },
                    { name: 'Description', index: 'Description', width: 250, editable: true, editoptions: { size: 250} },
                    { name: 'Reference', index: 'Reference', width: 200, editable: true, edittype: "select", editoptions: { value: returnRefList()} },
                    { name: 'Inactive', index: 'Inactive', width: 60, align: "center", editable: true, edittype: "checkbox", formatter: 'checkbox', formatoptions: { disabled: true} }
                    ],
    rowNum: 100,
    rowList: [100, 200, 300],
    pager: $('#LOINav'),
    sortname: 'LOI Number',
    viewrecords: true,
    sortorder: "desc",
    caption: "Lines of Inquiry",
    editurl: "Restful.svc/SaveLOI",
    onSelectRow: function (id) {
        if (id && id !== lastsel) {
            jQuery('#LOIEdit').jqGrid('saveRow', lastsel);
            jQuery('#LOIEdit').jqGrid('editRow', id, true);
            lastsel = id;
        }
    },
    gridComplete: function () { 
        if (reloadLOIGrid) {
            reloadLOIs();
        } 
    },
    ajaxGridOptions: { cache: false },
    loadonce: false
}).navGrid('#LOINav', { edit: false, add: false, del: false, search: false });

}

0 个答案:

没有答案