jqgrid編輯列

1.要編輯的列必須設置屬性爲true:editable: true,//可編輯

2.使用jqgrid  點擊事件:onSelectRow  注意:lastsel的定義

  onSelectRow : function(id) {
                        //lastsel:上一列id   id:當前id
                        if (id && id !== lastsel) {
                          jQuery('#form-appgrant-grid-table').jqGrid('saveRow', lastsel, true);
                          jQuery('#form-appgrant-grid-table').jqGrid('restoreRow', lastsel);
                          jQuery('#form-appgrant-grid-table').jqGrid('editRow', id, true);    
                          lastsel = id;
                        }
                        
                   },

這樣就可以編輯了,也就是選中當前行編輯,點擊下一行時當前行就保存

3.如何保存列表中編輯的值到數據庫

             //獲取列表所有
              var rowdata=$("#form-appgrant-grid-table").jqGrid('getRowData');
              //判斷列表中是否存在內容 
              if(rowdata.length>0){
                 
                  var id=1;
                  //先循環保存列表所有數據 ,不然獲取會帶有文本框,而不能真正獲取到值
                  $.each(rowdata,function(k,v){
                      
                      jQuery('#form-appgrant-grid-table').jqGrid('saveRow', id);
                      ++id;
                  })

                  //再從新獲取  ,這裏纔是得到真正的值
                  var refreshAfterData=$("#form-appgrant-grid-table").jqGrid('getRowData');
                  var ids="";
                  var grantfinishtimes="";
                  $.each(refreshAfterData,function(k,v){
                      //列表保存所有數據
                      jQuery('#form-appgrant-grid-table').jqGrid('saveRow', id);
                      ids+=v.epid+",";
                      grantfinishtimes+=v.grantfinishtime+",";
                  })
                   $.ajax({
                        type:"get",
                        dataType:"json",//預期服務器返回的數據類型,如果不設置 的json數據接收不了
                        url:getRootPath()+"/admin/updateGrantAcessAppStatus",
                        data:{"ids":ids.slice(0,ids.length-1),"grantfinishtimes":grantfinishtimes},
                        success:function(result){
                            if(result.status=='0')
                            {
                                Power.dialog.alertSuccess('添加成功!');
                                doQueryAppFund(null);
                            }
                            else{
                                Power.dialog.alertError('添加失敗,請稍後再試!');
                            }
                        }
                    })
              }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章