2

这里是Size的多选,它是根据样式值填充的。最初它是空的。

当我更改任何大小的选择时,不会触发 dataevent 更改。我在这里做错了什么?

    <script language="javascript" type="text/javascript">
function setHiddensizes(e)
{
    var sizesId = $(e.target).val();
    var row = $(e.target).closest('tr.jqgrow');
    var rowId = row.attr('id');
    $("#" + rowId +"_sizesId").val(sizesId);
}
            var i = 1;
            var lastSelection=0;
            $(function()
            {
                 $("#curruntppeGridgrid").jqGrid({
                        url:'getcostperformancecurreuntPPE',
                        datatype: "json",
                        jsonReader:{"repeatitems":false,unformat:Unformat_Select},
                        colNames:['Action','surveyId','applicationId','CategoryId','ManufacturerId','StyleId','UOMId','averagelifetimeselectId','sizesId','vp2Id','gridid',
                                    'recordId','Category','Manufacturer','Style','UOM','Count','Unit','Qty','Cost','Sizes','Annual Cost','VP2'], 
                        colModel:[{name:'id',index:'id',hidden:true,key:true},
                                    {name:'surveyId',index:'surveyId',hidden:true,editable:true},
                                    {name:'applicationId',index:'applicationId',hidden:true,editable:true},
                                    {name:'categoryId',index:'categoryId',hidden:true,editable:true},
                                    {name:'manufacturerId',index:'manufacturerId',hidden:true,editable:true},
                                    {name:'styleId',index:'styleId',hidden:true,editable:true},
                                    {name:'uomId',index:'uomId',hidden:true,editable:true},
                                    {name:'averagelifetimeselectId',index:'averagelifetimeselectId',hidden:true,editable:true},
                                    {name:'sizesId',index:'sizesId',hidden:true,editable:true},
                                    {name:'vp2Id',index:'vp2Id',hidden:true,editable:true},
                                    {name:'gridId',index:'gridId',hidden:true,editable:true,editoptions:{defaultValue:'current'}},
                                    {name:'recordId',index:'recordId',hidden:true,editable:true},

                                    {name:'category',index:'category',align:'center',editable: true, hidden: false, edittype: 'select',
                                   editoptions: { multiple: false, value: eval('(' + catList + ')'),
                                   dataEvents: [{
                                                type: 'change',
                                                fn:function(e){
                                                loadStyle(e);
                                                }}]},
                                   editrules: {required:false,custom:true,custom_func:categorycheck}
                                   },
                                   {name:'manufacturer',index:'manufacturer',align:'center', editable: true, hidden: false, edittype: 'select',
                                   editoptions: { value:eval('(' + manufList + ')'),
                                   dataEvents: [{
                                                type: 'change',
                                                fn:function(e){
                                                loadStyle(e);
                                                }}]},
                                   editrules: {required:false}
                                     },
                                   {name:'style',index:'style',align:'center',editable: true, hidden: false, edittype: 'select',
                                   editoptions: { multiple: false, value: eval('('+styleList+')'),
                                   dataInit: function (elem) {
                                   var v = $(elem).val();
                                    if(v!='')
                                    {
                                        var data = loadSizes(elem);
                                        jQuery('#curruntppeGridgrid').setColProp('sizes',{editoptions:{multiple:true,value:data}});
                                        var data1 = loadUom(elem);
                                        jQuery('#curruntppeGridgrid').setColProp('uom',{editoptions:{value:data1}});                        
                                    }
                                    else
                                        {
                                            jQuery('#curruntppeGridgrid').setColProp('sizes',{editoptions:{multiple:true,value:{}}});
                                            jQuery('#curruntppeGridgrid').setColProp('uom',{editoptions:{value:{}}}); 
                                        }
                                            },
                                    dataEvents: [{
                                                type: 'change',
                                                fn:function(e){
                                                loadCategoryAndManufacturer(e);
                                                }}]

                                   },
                                   editrules: { required: true}},
                                   {name:'uom',index:'uom',align:'center', editable: true, hidden: false, edittype: 'select',
                                   editoptions: { multiple: false, value:eval('(' + uomfList + ')'),
                                   dataEvents: [{
                                                type: 'change',
                                                fn:function(e){
                                                setHiddenUom(e);
                                                }}]
                                             },
                                   editrules: { required: false }},

                                   {name:'averagelifetime',index:'averagelifetime',editable:true,align:'center',sortable:false,editrules:{integer:true},
                                   editoptions:{class:'validate[custom[numbersOnly]]',
                                    dataEvents: [{
                                                type: 'click',
                                                fn:function(e){
                                                $('#formQuickSurvey').validationEngine({promptPosition:'bottomLeft',validationEventTrigger:'keyup'});
                                                }
                                                },
                                                {
                                                type: 'change',
                                                fn:function(e){
                                                setQty(e);
                                                }
                                                }
                                                ]}
                                   },

                                   {name:'averagelifetimeselect',index:'averagelifetimeselect',editable:true,align:'center',edittype: 'select',
                                   editoptions:{ multiple: false, value: eval('(' + avglifetimelist + ')'),
                                   dataInit: function (elem) {
                                                                var v = $(elem).val();
                                                                if(v!=''){
                                                                        jQuery('#curruntppeGridgrid').setColProp('averagelifetimeselectId', { editoptions: { defaultValue:v}} );
                                                                    }
                                                                },
                                   dataEvents: [{
                                                type: 'change',
                                                fn:function(e){
                                                setHiddenaveragelifetimeselect(e);
                                                setQty(e);
                                                }}]
                                                },
                                   editrules: { required: false }},

                                   {name:'qty',index:'qty',align:'center',editable:true,editrules:{integer:true},
                                   editoptions:{class:'validate[custom[numbersOnly]]',
                                    dataEvents: [{
                                                type: 'change',
                                                fn:function(e){
                                                calculateannualCost(e);
                                                }
                                                },{
                                                type:'click',
                                                fn:function(e){
                                                 $('#formQuickSurvey').validationEngine({promptPosition:'bottomLeft',validationEventTrigger:'keyup'});                                  
                                                }
                                                }]
                                                }
                                    },
                                   {name:'cost',index:'cost',align:'center',editable:true,editrules:{number:true},
                                   editoptions:{class:'validate[custom[number]]',
                                    dataEvents: [{
                                                type: 'change',
                                                fn:function(e){
                                                calculateannualCost(e);
                                                }
                                                },{
                                                type:'click',
                                                fn:function(e){
                                                 $('#formQuickSurvey').validationEngine({promptPosition:'bottomLeft',validationEventTrigger:'keyup'});                                  
                                                }
                                                }]
                                                }
                                    },                     
                                   {name:'sizes',index:'sizes',align:'center',edittype:'select',editable:true,editoptions:{multiple:true,value:{},
                                   dataInit: function (elem) {
                                                                    var v = $(elem).val();
                                                                    if(v!=''){
                                                                            jQuery('#curruntppeGridgrid').setColProp('sizesId', { editoptions: { defaultValue:v}} );
                                                                        }
                                                                    },
                                   dataEvents: [{
                                                type: 'change',
                                                fn:function(e){
                                                setHiddensizes(e);
                                                }}]
                                                }
                                                },
                                   {name:'annualCost',index:'annualCost',align:'center',editable: true, editoptions: { readonly: 'readonly' }},
                                   {name:'vp2',index:'vp2',align:'center',editable: true, hidden: false, edittype: 'select',
                                   editoptions: { multiple: false, value: eval('(' + vp2fList + ')'),
                                   dataInit: function (elem) {
                                                                var v = $(elem).val();
                                                                if(v!=''){
                                                                        jQuery('#curruntppeGridgrid').setColProp('vp2Id', { editoptions: { defaultValue:v}} );
                                                                    }
                                                                },
                                   dataEvents: [{
                                                type: 'change',
                                                fn:function(e){
                                                setHiddenvp2(e);
                                                validateCategoryandVP2(e);
                                                }}]
                                                 },
                                   editrules: { required: false }}                     
                                   ],
                        cmTemplate:{sortable:false},
                        width: eval('gridWidth()'),
                        pgbuttons:false,
                        pginput:false,
                        viewrecords:false,
                        //pager: '#curruntppeGridpager',
                        toppager:true,
                        multiselect:true,
                        editurl: 'editsurveyppe',
                        caption: 'Current PPE',
                        //forceFit:true,
                        hiddengrid:true,
                        hidegrid:true,
                        headertitles:true,
                        postData: { appId: function() { return $('#selectApplication option:selected').val(); }
                        },
                        onHeaderClick : function(gridstate){

                            if(gridstate == 'visible'){
                                $("#curruntppeGridgrid_toppager").show();
                            }
                            else{
                                $("#curruntppeGridgrid_toppager").hide();
                            }

                        },
                        loadComplete: function() {
                            $('#del_curruntppeGridgrid_top').removeClass('ui-state-disabled');//this is added to enable delete button after record reload
                            if(jQuery('#curruntppeGridgrid').jqGrid('getGridParam','gridstate')!='visible')
                            {
                                $("#curruntppeGridgrid_toppager").hide();
                            }
                            else{
                                $("#curruntppeGridgrid_toppager").show();
                            }
                        /*  if($("#${gridId}grid").getGridParam("records")==0 || $("#${gridId}grid").getGridParam("records")==false)
                            {
                                $('#del_${gridId}grid').addClass('ui-state-disabled');
                                $('#${gridId}grid_iledit').addClass('ui-state-disabled');
                            }
                            else
                                {
                                    $('#del_${gridId}grid').removeClass('ui-state-disabled');
                                    $('#${gridId}grid_iledit').removeClass('ui-state-disabled');
                                };*/
                        },
                        afterInsertRow:function(){//this is added to disable delete button while adding record
                            $('#del_curruntppeGridgrid_top').addClass('ui-state-disabled');

                        /*if($('#del_${gridId}grid').hasClass('ui-state-disabled'))
                                {

                                }*/
                        }
                        ,ajaxSelectOptions: { cache: false }

                    });

                    jQuery("#curruntppeGridgrid").jqGrid('navGrid',"#curruntppeGridpager",{cloneToTop:true,position:'right',edit:false,add:false,del:true,search:false,refresh:true,pgbuttons:false},
                            {},{},{mtype:'POST',reloadAfterSubmit:true,
                                serializeDelData: function (postdata) {
                                    var row = jQuery('#curruntppeGridgrid').getRowData(postdata.id);
                                    // append postdata with extra information 
                                    return {id: postdata.id, oper: postdata.oper,gridId:'current'};
                                }},{});

                    //top toolbar
                    jQuery("#curruntppeGridgrid").jqGrid('inlineNav','#curruntppeGridgrid_toppager',
                            {position:'right',editParams : {aftersavefunc:function()
                                {
                                    $("#curruntppeGridgrid").jqGrid().trigger("reloadGrid");
                                    $('#del_curruntppeGridgrid_top').removeClass('ui-state-disabled');//this is added to enable delete button after saveing record
                                },oneditfunc: function() {
                                    $('#del_curruntppeGridgrid_top').addClass('ui-state-disabled');//this is added to disable delete button while editing record
                                },
                                afterrestorefunc :function() {
                                    $('#del_curruntppeGridgrid_top').removeClass('ui-state-disabled');//this is added to enable delete button while cancelling record
                                    /*if($("#${gridId}grid").getGridParam("records")==0 || $("#${gridId}grid").getGridParam("records")==false)
                                    {
                                        $('#del_${gridId}grid').addClass('ui-state-disabled');
                                        $('#${gridId}grid_iledit').addClass('ui-state-disabled');
                                    }
                                    else
                                        {
                                            $('#del_${gridId}grid').removeClass('ui-state-disabled');
                                            $('#${gridId}grid_iledit').removeClass('ui-state-disabled');
                                        };*/
                                }
                                ,extraparam:{
                                    currentApplicationId: function() { return $("#selectApplication option:selected").val(); }
                                }
                              },

                              "restoreAfterSelect":false
                            });



                        jQuery('#curruntppeGridgrid').jqGrid('setGroupHeaders',{
                        useColSpanStyle: true,
                        groupHeaders:[{
                            startColumnName: 'averagelifetime',
                            numberOfColumns: 2,
                            titleText: '<em>Average Lifetime</em>'
                            }
                            ]});

            });     
            </script>

            <div id="curruntppeGridContainer" class="pad7 ansellGridContainer">
            <table id="curruntppeGridgrid" class="ansellGrid"></table>
            <div id="curruntppeGridpager" class="scroll" style="text-align:center;"></div>
            </div>

            <div id="curruntppeGriddialog" title="Feature not supported"
                style="display:none">
            <p>
            That feature is not supported.
            </p>
            </div>

            <div id="curruntppeGriddialogSelectRow" title="Warning" style="display:none">
            <p>
            Please select row
            </p>
            </div>
4

0 回答 0