记录OMgrid的选中行序号ID待数组中,并通过URL,将数组字符串化后传递到控制器

来源:互联网 发布:mac版spss许可 编辑:程序博客网 时间:2024/05/29 19:43

//可将选中行的ID,组合成一个字符串参数,传递到控制器


var selectIds = [];//存储选中的序号数组        //同理其他列数据也可以存储在数组中

 $(document).ready(function() {

$('#grid').omGrid({
                title : '明细内容',
                limit : 20,              
                showIndex : true,            
                singleSelect : false,
                colModel : [ {header : '顺序号',   name : 'inventoryItemId', width : 30, align : 'center',sort:'clientSide'},
                             {header : '物料编码', name : 'inventoryItemCode', width : 150, align : 'center',sort:'clientSide'},                             
                             {header : '创建者', name : 'createdBy', width : 'autoExpand', align : 'left',sort:'clientSide'}
                           ],
                    onRowSelect : function(index, data){
                        if($.inArray(data.inventoryItemId, selectIds)== -1)
                               selectIds.push(data.inventoryItemId);
                    },
                    onRowDeselect: function(index, data){
                        var i = $.inArray(data.inventoryItemId, selectIds);
                        selectIds.splice(i,1);

                    },
                    //还原过去选中的记录
                    onRefresh : function(nowpage, records){
                        var len = selectIds.length;
                        var indexs = [], index =-1;
                        for(var i=0; i<len; i++){
                           $.each(records, function(n,item){
                               if(item.inventoryItemId=== selectIds[i]){
                                         indexs.push(n);
                               }
                           });
                        }
                        
                        $("#grid").omGrid("setSelections", indexs);
                    }
            });

         });
                
//---------------------------------------调用----------------------------------

onClose:function(v){                           
                           if(v)
                           {
                                   var text="";
                                $.each(selectIds,function(i,item){
                                    text = text+ item+",";
                                }
);
                                //alert("您选择的记录有:"+text);//以逗号分隔开来
                                var text_encode =  encodeURIComponent(text);
                                   pathUrLupdate +="&selectIds="+text_encode;
                           
                                     
                                     $('#set_item_OF_flag').omButton('disable'),//失效按钮,避免多次提交//pathUrLupdate中传递组合成的ID字符串text_encode
                                   $('#formUpdateMeasureUnit').omAjaxSubmit({     url :pathUrLupdate,
                                                         target: '#output',         
                                                                                
                                                        success: showResponseUpdateFlag
                                    });
                            }
                          }//onClose


原创粉丝点击