Jqgrid上一页下一页表格编辑中的操作

时间:2014-12-01 08:02:01

标签: jquery jqgrid

我有一个使用多选的网格。当我选择多列并按下编辑时,我试图这样做,在编辑表单中,我只想在这些选定的行上显示下一个操作。我在编辑时尝试了onclickPgButtons事件,但我无法做到这一点。只是无法控制选定的行。有人可以帮助解决这个问题吗? 我怎么能这样做?

        $.extend($.jgrid.edit, {
            closeAfterAdd: false,
            jqModal: false,
            height: 'auto', width: 'auto',
            recreateForm: true,
            reloadAfterSubmit:false,
            afterSubmit: function (response) {
                RowInserted();
                return [true];
            },
            afterclickPgButtons: function (whichButton, formid, justSelectedRowid) {
                $(this).jqGrid("setSelection", justSelectedRowid);
            },

            onclickPgButtons: function (whichbutton, formid, rowid) {

                var selRowIds = $("#SampleGrid").jqGrid('getGridParam', 'selarrrow');
                if (whichbutton == 'next') {
                    console.log(selRowIds);
                    var next = nextProject(rowid, selRowIds);
                    console.log(next);
                    $("#SampleGrid").jqGrid('editGridRow', next, { jqModal: false, reloadAfterSubmit: false, closeAfterAdd: false });
                }
                if (whichbutton == 'prev') {
                    var prev = prevProject(rowid, selRowIds);
                    console.log(prev);
                    $("#SampleGrid").jqGrid('editGridRow', prev, { jqModal: false, reloadAfterSubmit: false, closeAfterAdd: false });
                }


            },


        });
        var lastSel;
        $("#SampleGrid").jqGrid({
            url: url,
            editurl: "/Finding/EditRow",
            datatype: 'json',
            mtype: 'Post',
            pager: '#pager',
            sortable: true,
            height: 'auto',
            viewrecords: true,
            caption: "Bulgu Girişi",
            rowNum: 10,
            rownumbers: true,
            autowidth: true,
            rowList: [10, 20, 30],
            multiselect: true,
            multiboxonly: true,
            shrinkToFit: false,
            postData: form,
            colNames: ['Id', 'Müşteri No', 'İş Kolu', 'Yetki Düzeyi', 'İşlemi Yapan Personel', 'Kontrole Konu Ürün/İşlem', 'Ürün Ref No', 'Ürün Bakiyesi/Riski', 'Para Cinsi', 'Kontrol Noktası', 'Bulgu Açıklaması', 'İlave Açıklama Bilgi', 'Tespit Edilen Eksiklik Tutarı', 'Tamamlanan Eksiklik Tutarı', 'Nihai Eksiklik Tutarı', 'Para Cinsi', 'Bulgu Statüsü', 'Özel',''],
            colModel:
                [   { name: 'Id', index: 'Id', hidden: true, sorttype: "guid", key: true },
                    { name: 'CustomerNo', index: 'CustomerNo', editable: false, align: 'center', width: 200, edittype: 'text', sopt: ['cn'], editrules: { required: true }, editoptions: { maxlength: 10 } },
                    {
                        name: 'BusinessLine', index: 'BusinessLine', editable: false, align: 'center', width: 200, edittype: 'select', sopt: ['cn'], editrules: { required: true }, editoptions:
                              {

                                  value: data.BusinessLine,
                                  datainit: function (elem) {
                                      if($('#slcBusinessLine option:selected').val()!="")
                                      {
                                          $(elem).select2('val', $('#slcBusinessLine option:selected').val());
                                          $(elem).prop('disabled', true);
                                      }
                                  }

                              },
                        stype: "select",
                        searchoptions: { stype: 'select', value: data.BusinessLine }, formatter: 'select'
                    },
                    {
                        name: 'AuthorityLevel', index: 'AuthorityLevel', editable: false, align: 'center', width: 200, edittype: 'select', sopt: ['cn'], editrules: { required: false },
                        editoptions:
                            {
                                value: data.AuthorityLevel
                            },
                        stype: "select",
                        formatter: 'select'
                    },
                    { name: 'ProcessOwnerNumber', index: 'ProcessOwnerNumber', editable: true, align: 'center', width: 200, edittype: 'text', sopt: ['cn'], editrules: { required: true }, editoptions: { maxlength: 6 } },
                    {
                        name: 'Product', index: 'Product', editable: false, align: 'center', width: 200, edittype: 'select', sopt: ['cn'], editrules: { required: true }, editoptions:
                              {
                                  value: data.Product,

                              },
                        stype: "select",
                        formatter: 'select'
                    },
                    { name: 'ProductRefNo', index: 'ProductRefNo', editable: true, align: 'center', width: 200, edittype: 'text', sopt: ['cn'], editrules: { required: true }, editoptions: { maxlength: 15 } },
                    {
                        name: 'ProductBalanceRisk', index: 'ProductBalanceRisk', editable: false, align: 'center', width: 200, edittype: 'text', sopt: ['cn'], editrules: { required: true }, editrules: {
                            required: true,
                            maxlength: 9

                        },
                        formatter: 'number',
                        formatoptions: { thousandsSeparator: ",", decimalPlaces: 0 },
                        editoptions: {
                            dataInit: function (elem) {
                                $(elem).autoNumeric({ vMax: '999999999', aSep: ',', aPad: false, aDec: ' ' });
                            },
                        }
                    },
                    {
                        name: 'FirstCurrency', index: 'FirstCurrency', editable: false, align: 'center', width: 200, edittype: 'select', sopt: ['cn'], editrules: { required: true }, editoptions: {
                            value: data.Currency

                        },
                        stype: "select",
                        formatter: 'select'
                    },
                    {
                        name: 'ControlPoint', index: 'ControlPoint', editable: true, align: 'center', width: 200, edittype: 'text', sopt: ['cn'], editrules: { required: true },

                    },
                    {
                        name: 'FindingExplanation', index: 'FindingExplanation', editable: true, align: 'center', width: 200, edittype: 'text', sopt: ['cn'], editrules: { required: true }, 
                    },
                    { name: 'AdditionalInfo', index: 'AdditionalInfo', editable: true, align: 'center', width: 200, edittype: 'text', sopt: ['cn'], editrules: { required: false }, editoptions: { maxlength: 100 } },
                    {
                        name: 'DeficiencyAmount', index: 'DeficiencyAmount', editable: true, align: 'center', width: 200, edittype: 'text', sopt: ['cn'],
                        editrules: {
                            required: true,
                            maxlength: 9

                        },
                        formatter: 'number',
                        formatoptions: { thousandsSeparator: ",", decimalPlaces: 0 },
                        editoptions: {
                            dataInit: function (elem) {
                                $(elem).autoNumeric({ vMax: '999999999', aSep: ',',aPad:false,aDec:' ' });
                            },
                            dataEvents: [{
                                type: 'keypress', fn: function (e) {
                                    var rowId = $grid.jqGrid('getGridParam', 'selrow');
                                    var firstValue = $(e.target).autoNumeric('get');
                                    if (rowId != null) {
                                        var secondValue = $('#' + rowId + '_ComplitedDeficiency').autoNumeric('get');
                                        if (secondValue == "") {
                                            secondValue = 0;
                                        }
                                        $('#' + rowId + '_FinalDeficiencyAmount').autoNumeric('set', parseFloat(firstValue) - parseFloat(secondValue));
                                    }
                                    else
                                    {
                                        var secondValue = $('#ComplitedDeficiency').autoNumeric('get');
                                        if (secondValue == "") {
                                            secondValue = 0;
                                        }
                                        $('#FinalDeficiencyAmount').autoNumeric('set', parseFloat(firstValue) - parseFloat(secondValue));
                                    }
                                    console.log(secondValue);
                                    console.log(firstValue - secondValue);
                                    //$('#' + rowId + '_FinalDeficiencyAmount').autoNumeric({ vMax: '999999999', aSep: ',', aPad: false, aDec: ' ' });

                                }
                            }]
                        },
                        },


                    {
                        name: 'ComplitedDeficiency', index: 'ComplitedDeficiency', editable: true, align: 'center', width: 200, edittype: 'text', sopt: ['cn'], editrules: { required: true }, editrules: {
                            required: true,
                            maxlength: 9

                        },
                        formatter: 'number',
                        formatoptions: { thousandsSeparator: ",", decimalPlaces: 0 },
                        editoptions: {
                            dataInit: function (elem) {
                                $(elem).autoNumeric({ vMax: '999999999', aSep: ',', aPad: false, aDec: ' ' });
                            },
                            dataEvents: [{
                                type: 'keypress', fn: function (e) {
                                    var rowId = $grid.jqGrid('getGridParam', 'selrow');
                                    var secondValue = $(e.target).autoNumeric('get');
                                    if (rowId != null) {
                                        var firstValue = $('#' + rowId + '_DeficiencyAmount').autoNumeric('get');
                                        if (firstValue == "") {
                                            firstValue = 0;
                                        }
                                        $('#' + rowId + '_FinalDeficiencyAmount').autoNumeric('set', parseFloat(firstValue) - parseFloat(secondValue));
                                    }
                                    else
                                    {
                                        var firstValue = $('#DeficiencyAmount').autoNumeric('get');
                                        if (firstValue == "") {
                                            firstValue = 0;
                                        }
                                        $('#FinalDeficiencyAmount').autoNumeric('set', parseFloat(firstValue) - parseFloat(secondValue));
                                    }

                                    //$('#' + rowId + '_FinalDeficiencyAmount').autoNumeric({ vMax: '999999999', aSep: ',', aPad: false, aDec: ' ' });

                                }
                            }]
                        }
                    },

                    {
                        name: 'FinalDeficiencyAmount', index: 'FinalDeficiencyAmount', editable: true, align: 'center', width: 200, edittype: 'text', sopt: ['cn'], editrules: { required: true },
                        formatter: 'number',
                        formatoptions: { thousandsSeparator: ",", decimalPlaces: 0 },
                        editoptions: {
                            readonly: true,
                            dataInit: function (elem) {
                                $(elem).autoNumeric({ vMax: '999999999', aSep: ',', aPad: false, aDec: ' ' });
                            }
                        }

                    },
                    {
                        name: 'SecondCurrency', index: 'SecondCurrency', editable: true, align: 'center', width: 200, edittype: 'select', sopt: ['cn'], editrules: { required: true }, editoptions: {
                            value: data.Currency

                        },
                        stype: "select",
                        formatter: 'select'
                    },
                    {
                        name: 'FindingStatus', index: 'FindingStatus', editable: true, align: 'center', width: 200, edittype: 'select', sopt: ['cn'], editrules: { required: true },
                        editoptions:
                            {
                                value: "1:Genel Tenkit;2:GM Bildirim;3:Açık;4:Kapalı Şube"
                            },
                        stype: "select",
                        formatter: 'select'
                    },
                    { name: 'IsSpecial', index: 'IsSpecial', editable: false, align: 'center', width: 200, edittype: 'checkbox', sopt: ['cn'], editrules: { required: true }, editoptions: { value: "True:False" }, formatter: 'checkbox' },
                    { name: 'EnableAdditionalInfo', index: 'EnableAdditionalInfo', hidden:true},
                ],
            //grouping: true,
            //groupingView: {
            //    groupField: ['CustomerNo','BusinessLine'],

            //    groupColumnShow: [false]
            //    //groupField: ['AuthorityLevel'],
            //    //groupField: ['ProductRefNo'],

            //},
            afterInsertRow: function (rowId, rdata) {

            },

            //beforeProcessing: function (response) {

            //    var $self = $(this), options = $grid.jqGrid('getGridParam', 'colModel'), p,
            //        needRecreateSearchingToolbar = false;
            //    if (options != null) {

            //        for (p in options) {
            //            if (options.hasOwnProperty(p)) {
            //                if (options[p].edittype === "select") {
            //                    options[p].editoptions.dataInit = initSelect2;
            //                }
            //                if (options[p].stype === "select") {
            //                    options[p].searchoptions.dataInit = initSelect2;
            //                }
            //                $self.jqGrid("setColProp", p, options[p]);
            //                if (!this.ftoolbar) { // filter toolbar exist
            //                    needRecreateSearchingToolbar = true;
            //                }
            //            }
            //        }
            //        if (needRecreateSearchingToolbar) {
            //            //alert("sss");
            //            $self.jqGrid("destroyFilterToolbar");
            //            //$self.jqGrid("filterToolbar", filterToolbarOptions);
            //        }
            //    }
            //},
            beforeRequest: function () {
                responsive_jqgrid($(".grid_box"));
            },


            onSelectRow: function (id) {
                //if (id && id !== lastSel) {
                //    if (typeof lastSel !== "undefined") {
                //        $("#SampleGrid").jqGrid('restoreRow', lastSel);
                //    }
                //    lastSel = id;
                //}
            }
        });
        $('#SampleGrid').jqGrid('navGrid', '#pager', {
            edit: true, add: false, del: false, search: false,
            editfunc: function (rowid) {
                var selRowIds = $("#SampleGrid").jqGrid('getGridParam', 'selarrrow');
                if (selRowIds != null) {
                    var firstSelectedRow = selRowIds[0];
                    $("#SampleGrid").jqGrid('editGridRow', firstSelectedRow, { jqModal: false, reloadAfterSubmit: false, closeAfterAdd: false });

                }

            }

        });

    });

}
function nextProject(num, array) {
    console.log($.inArray(num, array));

    return array[($.inArray(num, array) + 1) % array.length];
}
function prevProject(num,array) {
    return array[($.inArray(num, array) - 1 + array.length) % array.length];
}

1 个答案:

答案 0 :(得分:0)

我处理了编辑jqgrid.js的问题。再次感谢@Oleg