2011-12-27 83 views
0

我是jquery的新手。我的要求是我需要在Jqgrid中显示MultiLine文本框的值,并允许用户编辑它。由于我的网格有很多列,我想当用户在jqgrid中编辑多行文本框时,弹出一个小窗口,用户可以在其中输入值并单击按钮时,该值将返回到jqgrid中的多行文本框。如何从Jqgrid单元格打开一个小窗体或窗口编辑

再次当用户想要看到它们时,单击多行框应打开输入文本的窗口。

任何人都可以帮助我吗?

感谢


下面是我的网details..Its可编辑网格。我的要求是在用户点击Freq Missed问题栏时打开弹出窗口。

function loadCustomerBenefitResultsGrid() 
    {  
    var lastsel; 
      jQuery("#CustomerSavingsView").jqGrid(
        { 
         dataType:"local", 
         colNames: ['UID','Date','QPlus Savings', 
        'Savings Available', 
      'Consignment Savings','Cost Increases','Distribution Fees', 
      'Clinical Review', 'Inventory Red','Clinical Time', 
      'Logistical Time', 
     'SpaceUtil Time','GreenSmart Savings','Gold Standard', 
     '%Staff Engaged in Courses','InsertUpdateDel','IsEdited', 
     'CustomerID','GreenItems in Trays','SSF Layout', 
     'StaffTest Scores','Freq Missed Questions','Popular Courses','Delete'], 
         colModel: [ 
          {name:'UID',index:'UID', width:40, sorttype:'string',"key": true,hidden:true}, 
          {name:'Date', index:'Date',width:100,align:'center', sorttype: 'string',editable:true, editoptions:{size:20, 
           dataInit:function(el) 
           {       
            $(el).datepicker({dateFormat:'mm/dd/yy'}); 

            }, 
             defaultValue: function() 
              {      
              var currentTime = new Date();      
              var month = parseInt(currentTime.getMonth() + 1);      
              month = month <= 9 ? "0"+month : month;      
              var day = currentTime.getDate();      
              day = day <= 9 ? "0"+day : day;      
              var year = currentTime.getFullYear(); 
                 return month+"/"+day + "/"+year;      
              }     
            }     
          },         
          { name: 'ProductSavings', index: 'ProductSavings',width:70,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'SavingsstillAvailable', index: 'SavingsstillAvailable',width:70,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'Consignment', index: 'Consignment',width:105,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'CostIncreases', index: 'CostIncreases',width:80,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'Distribution', index: 'Distribution',width:110,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'ClinicalReview', index: 'ClinicalReview',width:70,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'InventoryRed', index: 'InventoryRed',width:90,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'ClinicalTime', index: 'ClinicalTime',width:70,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'LogisticalTime', index: 'LogisticalTime',width:90,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'SpaceUtilTime', index: 'SpaceUtilTime',width:90,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'GreenSmart', index: 'GreenSmartSavings',width:90,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'GoldStandard', index: 'GoldStandard',width:80,align:'center', sorttype: 'string',editable: true,edittype: 'text',editoptions: { size: 10} }, 
          { name: 'StaffTestScores', index: 'StaffTestScores',width:80,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} },         
          { name: 'InsertUpdateDel', index: 'InsertUpdateDel',width: 100, align:'center', sorttype: 'string',hidden:true}, 
          { name: 'IsEdited', index: 'IsEdited',width: 40, align:'center', sorttype: 'string',hidden:true}, 
          { name: 'CustomerID', index: 'CustomerID',width: 40, align:'center', sorttype: 'string',hidden:true}, 
          { name: 'GreenItemsinTray', index: 'GreenItemsinTray',width:90,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'SpacestoragefacultyAnalysis', index: 'SpacestoragefacultyAnalysis',width:80,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} }, 
          { name: 'StaffEducationalCourses', index: 'StaffEducationalCourses',width:80,align:'center', sorttype: 'string',editable: true,edittype: 'text', editoptions: { size: 10} },  
          { name: 'FreqMissedQuestions', index: 'FreqMissedQuestions',width:200, sorttype: 'string',editable: true,edittype:"textarea", editoptions:{rows:"3",cols:"25"}} , 
          { name: 'PopularCourses', index: 'PopularCourses',width:150,sorttype: 'string',editable: true,edittype:"textarea", editoptions:{rows:"3",cols:"20"}} ,   
          { name: 'Delete', index: 'Delete',width: 90, align:'center' } 
         ], 
         height: 250, 
         width:1175, 
         gridview:true, 
         hidegrid: false, 
         viewrecords:true, 
         sortable: true,       
         sortname: 'Date', 
         sortorder: "asc", 
         editurl: "clientArray", 
         onSelectRow: function(id) { 
                  if (id && id !== lastsel) 
                  {  
                   jQuery("#CustomerSavingsView").saveRow(lastsel,false,'clientArray'); 
                   jQuery("#CustomerSavingsView").editRow(id,true); 
                   lastsel = id; 
                   //Get the current row 
                   var currentRow = jQuery("#CustomerSavingsView").getRowData(id);                  
                   //For Insert 
                   if(currentRow['InsertUpdateDel']!= null && currentRow['InsertUpdateDel'] == "Inserted") 
                   { 
                    changedRowsBeforeInsert.push(id); 
                   }                  
                   //For Update                 
                   if(currentRow['InsertUpdateDel']!= null && currentRow['InsertUpdateDel'] == "Updated") 
                   { 
                    changedRows.push(id); 
                   } 

                  } else 
                  { 
                   jQuery("#CustomerSavingsView").saveRow(lastsel,false,'clientArray'); 
                   jQuery("#CustomerSavingsView").editRow(id,true); 
                   lastsel = id;                 
                   //Get the current row 
                   var currentRow = jQuery("#CustomerSavingsView").getRowData(id); 
                   //For Insert 
                   if(currentRow['InsertUpdateDel']!= null && currentRow['InsertUpdateDel'] == "Inserted") 
                   { 
                    changedRowsBeforeInsert.push(id); 
                   } 
                   //For Update 
                   if(currentRow['InsertUpdateDel']!= null && currentRow['InsertUpdateDel'] == "Updated") 
                   { 
                    changedRows.push(id); 
                   }                  
                  }                

                  //Limit the Keypress 
                  $('input[name=ProductSavings]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=Consignment]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=CostIncreases]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=Distribution]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=ClinicalReview]').limitkeypress({ rexp:/^[+]?\d*\.?\d*$/ }); 
                  $('input[name=InventoryRed]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=ClinicalTime]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=LogisticalTime]').limitkeypress({ rexp:/^[+]?\d*\.?\d*$/ }); 
                  $('input[name=SpaceUtilTime]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=GreenSmart]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=StaffTestScores]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=SavingsstillAvailable]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=GreenItemsinTray]').limitkeypress({ rexp:/^[+]?\d*\.?\d*$/ }); 
                  $('input[name=SpacestoragefacultyAnalysis]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ }); 
                  $('input[name=StaffEducationalCourses]').limitkeypress({ rexp: /^[+]?\d*\.?\d*$/ });                

                },        
         gridComplete: function() { 
                 var ids = jQuery("#CustomerSavingsView").jqGrid('getDataIDs'); 
                 if (ids.length > 0) 
                 { 
                  for (var i = 0; i < ids.length; i++) 
                  { 
                   var cl = ids[i]; 
                   cb = "<input type='checkbox' id='chkDelete"+cl+"' value='" + cl + "' />"; 
                   jQuery("#CustomerSavingsView").jqGrid('setRowData', cl, { Delete: cb}); 
                  } 
                 } 
                } 


     });     

}

+0

签名被删除,请参阅FAQ。 – 2011-12-28 04:55:10

回答

1

开始参照本页面:http://www.trirand.com/jqgridwiki/doku.php?id=wiki:events

查找选项onCellSelect,这是你需要听绑定事件。

onCellSelect : function (rowid,iCol, cellcontent, e) { 
// ... 
} 

在这种情况下,检查以确保ICOL是您的特定文本框格的索引(因为此事件将触发对每一个细胞,而您只需要这个功能对于特定的一个)。如果它是正确的单元格,那么您有几种方法可以完成实际的编辑。我会通过弹出一个嵌入窗体打开jQuery UI modal dialog来做到这一点。我也将使用jquery填充单击的记录的rowID的表单内容,并加载一个textarea字段与单元格的当前值(可在您的事件处理程序中作为cellcontent)。然后,您可以使用jQuery的Ajax表单提交选项(请参阅.serialize()$.ajax())将新值发回服务器,以在后端更新值(即数据库更新)。最后,在您的Ajax成功处理程序中,关闭模式对话框并在您的表上运行.trigger("reloadGrid");,以使用当前值重新加载网格。

+0

谢谢你杰克。让我试试这个,你会知道结果。感谢您的帮助.. – siv 2011-12-28 16:30:12

+0

嗨Jake,单元格选择事件只在第一次点击单元格时触发。随后的时间事件根本不会触发。例如。我点击一个特定的单元格,事件触发,再次点击单元格事件不会触发。我错过了什么吗? – siv 2011-12-30 16:41:22

+0

我正在使用单元格编辑,我认为这在我们使用单元格编辑时不可用。任何其他方法杰克? – siv 2011-12-30 16:44:40

相关问题