JqG​​rid:只能检索当前页面的选定ID

时间:2014-06-06 04:11:05

标签: jquery jqgrid

我有一个带multiselect =true选项的Jqgrid以及分页。我的页面大小是10,在编辑过程中如果有更多的记录,那么页面大小会进入2页。这工作正常。

我的查询是,如果我在当前页面上并直接保存数据而不进入下一页,那么我的数组只有10条记录而该数据被保存,其他记录将被删除。

请帮我纠正这个问题

这是我的代码

    $("#WorkerMigrationSearchGrid").jqGrid({
    datatype: '',
    height: 340,
    width: 910,
    colNames: ['WorkerID', 'Worker Name', 'IC / FIN', 'WP No', 'BusinessUnitID', 'PrimarySubContractorID', 'Status', 'PrimaryTradeID'],
    colModel: [
    { name: 'WorkerID', index: 'WorkerAttendanceID', width: 1, hidden: true },
    { name: 'Worker', index: 'Worker', width: 200, sortable: false },
    { name: 'IdentificationNumber', index: 'IdentificationNumber', width: 50, sortable: false },
    { name: 'WPNumber', index: 'WPNumber', width: 50, sortable: false },
    { name: 'BusinessUnitID', index: 'ScanTime', width: 90, sortable: false, hidden: true },
    { name: 'PrimarySubContractorID', index: 'ScanType', width: 30, sortable: false, hidden: true },
    { name: 'Status', index: 'Status', width: 1, hidden: true },
    { name: 'PrimaryTradeID', index: 'PrimaryTradeID', width: 1, hidden: true }
],
    multiselect: true,
    caption: "Select Worker",
    pager: jQuery('#pager'),
    viewrecords: true,
    scrollrows: true,
    shrinkToFit: true,
    rowNum: 10,
    rowList: [10, 15, 20],        // disable page size dropdown
    pgbuttons: true,
    pgtext: "Page {0} of {1}",
    altRows: true,
    onSelectAll: function (rowid, isSelected) {
        idsOfSelectedRows = [];

        if (isSelected) {

            var i, count, id
            for (i = 0, count = rowid.length; i < count; i++) {
                id = rowid[i];
                updateIdsOfSelectedRows(id, isSelected);

            }

        }
        //idsOfSelectedRows.push(id);
    },
    onSelectRow: function (id, isSelected) {
        updateIdsOfSelectedRows(id, isSelected);
    },
    gridComplete: function () {
        var i, selCount;
        for (i = 0, selCount = idsOfSelectedRows.length; i < selCount; i++) {

            row = $("#WorkerMigrationSearchGrid").getRowData(idsOfSelectedRows[i])

            if (row["WorkerID"] != undefined) {

                jQuery("#WorkerMigrationSearchGrid").jqGrid('setSelection', row["WorkerID"]);

            }

        }

    },
    onPaging: function (pgButton) {
        SearchWorker();
    }
});

var updateIdsOfSelectedRows = function (id, isSelected) {
    var p = $("#WorkerMigrationSearchGrid").p, item = $("#WorkerMigrationSearchGrid").getRowData(id);
    item.cb = isSelected;
    i = $.inArray(id, idsOfSelectedRows);
    if (!isSelected && i >= 0) {

        idsOfSelectedRows.splice(i, 1); // remove id from the list

    } else if (i < 0) {

        idsOfSelectedRows.push(id);

    }
}

0 个答案:

没有答案