<script type="text/javascript"> var lastsel2 jQuery("#rowed4").jqGrid({ url:'server.php?q=2', datatype: "json",//datatype: "local", colNames: ['Inv No','Date', 'Client', 'Amount','Tax','Total','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"}},//文本框,值的最大长度30 {name:'amount',index:'amount', width:80, align:"right",editable:true}, {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"}//多行文本区域 ], rowNum: 10, rowList: [10,20,30], pager: '#prowed4', sortname: 'id', viewrecords: true, sortorder: "desc", onSelectRow: function(id){ if(id && id!==lastsel2){ jQuery('#rowed5').jqGrid('restoreRow',lastsel2); jQuery('#rowed5').jqGrid('editRow',id,true); jQuery('#rowed6').jqGrid('editRow',id,true,pickdates); lastsel2=id; } }, jsonReader: {//Data Optimization repeatitems : true, cell:"", id: "0" }, editurl: "server.php", caption: "Full control" }); jQuery("#43rowed3").jqGrid('navGrid',"#p43rowed3",{edit:false,add:false,del:false}); jQuery("#43rowed3").jqGrid('inlineNav',"#p43rowed3"); jQuery("#ed4").click( function() { jQuery("#rowed4").jqGrid('editRow',"13"); this.disabled = 'true'; jQuery("#sved4").attr("disabled",false); }); jQuery("#sved4").click( function() { jQuery("#rowed4").jqGrid('saveRow',"13", checksave); jQuery("#sved4").attr("disabled",true); jQuery("#ed4").attr("disabled",false); }); function checksave(result) { if (result.responseText=="") { alert("Update is missing!"); return false; } return true; } 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]); function pickdates(id){//UI Datepicker jQuery("#"+id+"_sdate","#rowed6").datepicker({dateFormat:"yy-mm-dd"}); } jQuery("#list19").jqGrid({ url: 'books.xml', datatype: "xml", colNames:["Author","Title", "Price", "Published Date"], colModel:[ {name:"Author",index:"Author", width:120, xmlmap:"ItemAttributes>Author"}, {name:"Title",index:"Title", width:180,xmlmap:"ItemAttributes>Title"}, {name:"Price",index:"Manufacturer", width:100, align:"right",xmlmap:"ItemAttributes>Price", sorttype:"float"}, {name:"DatePub",index:"ProductGroup", width:130,xmlmap:"ItemAttributes>DatePub",sorttype:"date"} ], height:250, rowNum:10, rowList:[10,20,30], viewrecords: true, loadonce: true, xmlReader: { root : "Items", row: "Item", repeatitems: false, id: "ASIN" }, caption: "XML Mapping example" }); </script>
... <table id="rowed4"></table> <div id="prowed4"></div> <br /> <input type="BUTTON" id="ed4" value="Edit row 13" /> <input type="BUTTON" id="sved4" disabled='true' value="Save row 13" /> <script src="rowedex4.js" type="text/javascript"> </script>books.xml
<Books> <Items> <Request> <IsValid>True</IsValid> <ItemSearchRequest> <SearchIndex>Books</SearchIndex> </ItemSearchRequest> </Request> <Item> <DetailPageURL/> <ItemAttributes> <Author>John Grisham</Author> <Title>A Time to Kill</Title> <Price>12.99</Price> <DatePub>1998-05-01</DatePub> <ASIN>0446351230</ASIN> </ItemAttributes> </Item> <Item> <DetailPageURL/> <ItemAttributes> <Author>Stephen King</Author> <Title>Blood and Smoke</Title> <Price>24.00</Price> <DatePub>2000-01-01</DatePub> <ASIN>0446355453</ASIN> </ItemAttributes> </Item> <Item> <DetailPageURL/> <ItemAttributes> <Author>John Grisham</Author> <Title>The Rainmaker</Title> <Price>7.99</Price> <DatePub>2001-12-01</DatePub> <ASIN>0443622434</ASIN> </ItemAttributes> </Item> <Item> <DetailPageURL/> <ItemAttributes> <Author>Stephen King</Author> <Title>The Green Mile</Title> <Price>24.00</Price> <DatePub>1992-01-01</DatePub> <ASIN>0443622987</ASIN> </ItemAttributes> </Item> <Item> <DetailPageURL/> <ItemAttributes> <Author>Stephen King</Author> <Title>Misery</Title> <Price>7.70</Price> <DatePub>2003-01-01</DatePub> <ASIN>0443623452</ASIN> </ItemAttributes> </Item> <Item> <DetailPageURL/> <ItemAttributes> <Author>Stephen King</Author> <Title>The Dark Half</Title> <Price>48.00</Price> <DatePub>1999-10-30</DatePub> <ASIN>0443623482</ASIN> </ItemAttributes> </Item> <Item> <DetailPageURL/> <ItemAttributes> <Author>John Grisham</Author> <Title>The Partner</Title> <Price>12.99</Price> <DatePub>2005-01-01</DatePub> <ASIN>0443744434</ASIN> </ItemAttributes> </Item> <Item> <DetailPageURL/> <ItemAttributes> <Author>Stephen King</Author> <Title>It</Title> <Price>9.70</Price> <DatePub>2001-10-15</DatePub> <ASIN>0443698452</ASIN> </ItemAttributes> </Item> <Item> <DetailPageURL/> <ItemAttributes> <Author>Honore de Balzac</Author> <Title>Cousin Bette</Title> <Price>19.70</Price> <DatePub>1991-12-01</DatePub> <ASIN>0443691234</ASIN> </ItemAttributes> </Item> <Item> <DetailPageURL/> <ItemAttributes> <Author>Alexandr Pushkin</Author> <Title>Boris Godunov</Title> <Price>7.15</Price> <DatePub>1999-01-01</DatePub> <ASIN>0447791234</ASIN> </ItemAttributes></Item> <Item> <DetailPageURL/> <ItemAttributes> <Author>Alice in Wonderland</Author> <Title>Lewis Carroll</Title> <Price>4.15</Price> <DatePub>1999-01-01</DatePub> <ASIN>0447791294</ASIN> </ItemAttributes> </Item> </Items> </Books>