【问题标题】:jQuery: jqGrid - creating a table where one can edit cellsjQuery: jqGrid - 创建一个可以编辑单元格的表格
【发布时间】:2010-10-04 02:10:07
【问题描述】:

各位, 我对 jQuery 和 JqGrid 都是全新的。通常我在四处询问之前会花一些时间来了解底层软件,但不幸的是我时间不够,所以我的问题可能有一个简单的答案(RTFM)。如果你能给出一个很好的替代答案:)

我正在尝试绘制一个简单的网格,可以在其中编辑单元格并保存它(在帖子中请求 url)。我想将生成的网格数据保存在 javascript 中或通过编辑 url。

我尝试了http://www.trirand.com/blog/jqgrid/jqgrid.html 的示例(单击行编辑 -> 输入类型),但我的页面上没有任何内容,也没有收到任何 js 错误。所有的 css 和 js 文件路径似乎都是准确的。

这是我尝试过的代码(我使用的是 jqGrid 3.8)(我查看了线程 jqgrid editoptions: required not functioning 但无法使其工作。)


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>My First Grid</title> 

<link rel="stylesheet" type="text/css" media="screen" href="css/custom-theme/jquery-ui-1.8.5.custom.css" /> 
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" /> 

 <style> 
html, body {
    margin: 0;
    padding: 0;
    font-size: 75%;
}
</style> 
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script> 
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script> 
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script> 
<script type="text/javascript"> 
var lastsel2;
jQuery("#rowed5").jqGrid({
 datatype: "local",
 height: 250,
    colNames:['ID Number','Name', 'Stock', 'Ship via','Notes'],
    colModel:[
     {name:'id',index:'id', width:90, sorttype:"int", editable: true},
     {name:'name',index:'name', width:150,editable: true,editoptions:{size:"20",maxlength:"30"}},
     {name:'stock',index:'stock', width:60, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"}},
     {name:'ship',index:'ship', width:90, editable: true,edittype:"select",editoptions:{value:"FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX"}},  
     {name:'note',index:'note', width:200, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"10"}}  
    ],
 onSelectRow: function(id){
  if(id && id!==lastsel2){
   jQuery('#rowed5').jqGrid('restoreRow',lastsel2);
   jQuery('#rowed5').jqGrid('editRow',id,true);
   lastsel2=id;
  }
 },
 editurl: "edit.html",
 caption: "Input Types"

});
var mydata2 = [
  {id:"12345",name:"Desktop Computer",note:"note",stock:"Yes",ship:"FedEx"},
  {id:"23456",name:"Laptop",note:"Long text ",stock:"Yes",ship:"InTime"},
  {id:"34567",name:"LCD Monitor",note:"note3",stock:"Yes",ship:"TNT"},
  {id:"45678",name:"Speakers",note:"note",stock:"No",ship:"ARAMEX"},
  {id:"56789",name:"Laser Printer",note:"note2",stock:"Yes",ship:"FedEx"},
  {id:"67890",name:"Play Station",note:"note3",stock:"No", ship:"FedEx"},
  {id:"76543",name:"Mobile Telephone",note:"note",stock:"Yes",ship:"ARAMEX"},
  {id:"87654",name:"Server",note:"note2",stock:"Yes",ship:"TNT"},
  {id:"98765",name:"Matrix Printer",note:"note3",stock:"No", ship:"FedEx"}
  ];
for(var i=0;i < mydata2.length;i++)
 jQuery("#rowed5").jqGrid('addRowData',mydata2[i].id,mydata2[i]);


</script> 

</head> 
<body> 
<table id="rowed5"></table> 
</body> 
</html> 

【问题讨论】:

    标签: jqgrid


    【解决方案1】:

    我在问题Spreadsheet-like inline editing in jqGrid 中找到了答案,@oleg 提供了一个链接http://www.ok-soft-gmbh.com/jqGrid/ClientsideEditing4.htm

    感谢@Oleg!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-16
      • 1970-01-01
      • 2011-03-18
      • 1970-01-01
      相关资源
      最近更新 更多