jqGrid 属性、事件全集(二)
1 <script type="text/javascript"> 2 var lastsel2 3 jQuery("#rowed4").jqGrid({ 4 url:'server.php?q=2', 5 datatype: "json",//datatype: "local", 6 colNames: ['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'], 7 colModel: [ 8 {name:'id',index:'id', width:90, sorttype:"int", editable: true},//文本框 9 {name:'name',index:'name', width:150,editable: true,editoptions:{size:"20",maxlength:"30"}},//文本框,值的最大长度30 10 {name:'amount',index:'amount', width:80, align:"right",editable:true}, 11 {name:'stock',index:'stock', width:60, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"}},//复选框 12 {name:'ship',index:'ship', width:90, editable: true,edittype:"select",editoptions:{value:"FE:FedEx;IN:InTime;TN:TNT;AR:ARAMEX"}}, //下拉框 13 {name:'note',index:'note', width:200, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"10"}//多行文本区域 14 ], 15 rowNum: 10, 16 rowList: [10,20,30], 17 pager: '#prowed4', 18 sortname: 'id', 19 viewrecords: true, 20 sortorder: "desc", 21 onSelectRow: function(id){ 22 if(id && id!==lastsel2){ 23 jQuery('#rowed5').jqGrid('restoreRow',lastsel2); 24 jQuery('#rowed5').jqGrid('editRow',id,true); 25 jQuery('#rowed6').jqGrid('editRow',id,true,pickdates); 26 lastsel2=id; 27 } 28 }, 29 jsonReader: {//Data Optimization 30 repeatitems : true, 31 cell:"", 32 id: "0" 33 }, 34 editurl: "server.php", 35 caption: "Full control" 36 }); 37 jQuery("#43rowed3").jqGrid('navGrid',"#p43rowed3",{edit:false,add:false,del:false}); 38 jQuery("#43rowed3").jqGrid('inlineNav',"#p43rowed3"); 39 40 jQuery("#ed4").click( function() { 41 jQuery("#rowed4").jqGrid('editRow',"13"); 42 this.disabled = 'true'; 43 jQuery("#sved4").attr("disabled",false); 44 }); 45 jQuery("#sved4").click( function() { 46 jQuery("#rowed4").jqGrid('saveRow',"13", checksave); 47 jQuery("#sved4").attr("disabled",true); 48 jQuery("#ed4").attr("disabled",false); 49 }); 50 function checksave(result) { 51 if (result.responseText=="") { 52 alert("Update is missing!"); 53 return false; 54 } 55 return true; 56 } 57 58 var mydata2 = [ 59 {id:"12345",name:"Desktop Computer",note:"note",stock:"Yes",ship:"FedEx"}, 60 {id:"23456",name:"Laptop",note:"Long text ",stock:"Yes",ship:"InTime"}, 61 {id:"34567",name:"LCD Monitor",note:"note3",stock:"Yes",ship:"TNT"}, 62 {id:"45678",name:"Speakers",note:"note",stock:"No",ship:"ARAMEX"}, 63 {id:"56789",name:"Laser Printer",note:"note2",stock:"Yes",ship:"FedEx"}, 64 {id:"67890",name:"Play Station",note:"note3",stock:"No", ship:"FedEx"}, 65 {id:"76543",name:"Mobile Telephone",note:"note",stock:"Yes",ship:"ARAMEX"}, 66 {id:"87654",name:"Server",note:"note2",stock:"Yes",ship:"TNT"}, 67 {id:"98765",name:"Matrix Printer",note:"note3",stock:"No", ship:"FedEx"} 68 ]; 69 for(var i=0;i < mydata2.length;i++) 70 jQuery("#rowed5").jqGrid('addRowData',mydata2[i].id,mydata2[i]); 71 72 function pickdates(id){//UI Datepicker 73 jQuery("#"+id+"_sdate","#rowed6").datepicker({dateFormat:"yy-mm-dd"}); 74 } 75 76 jQuery("#list19").jqGrid({ 77 url: 'books.xml', 78 datatype: "xml", 79 colNames:["Author","Title", "Price", "Published Date"], 80 colModel:[ 81 {name:"Author",index:"Author", width:120, xmlmap:"ItemAttributes>Author"}, 82 {name:"Title",index:"Title", width:180,xmlmap:"ItemAttributes>Title"}, 83 {name:"Price",index:"Manufacturer", width:100, align:"right",xmlmap:"ItemAttributes>Price", sorttype:"float"}, 84 {name:"DatePub",index:"ProductGroup", width:130,xmlmap:"ItemAttributes>DatePub",sorttype:"date"} 85 ], 86 height:250, 87 rowNum:10, 88 rowList:[10,20,30], 89 viewrecords: true, 90 loadonce: true, 91 xmlReader: { root : "Items", row: "Item", repeatitems: false, id: "ASIN" }, 92 caption: "XML Mapping example" 93 }); 94 </script>
1 <table id="rowed4"></table> 2 <div id="prowed4"></div> <br /> 3 <input type="BUTTON" id="ed4" value="Edit row 13" /> 4 <input type="BUTTON" id="sved4" disabled='true' value="Save row 13" /> 5 <script src="rowedex4.js" type="text/javascript"> </script>
books.xml
1 <Books> 2 <Items> 3 <Request> 4 <IsValid>True</IsValid> 5 <ItemSearchRequest> 6 <SearchIndex>Books</SearchIndex> 7 </ItemSearchRequest> 8 </Request> 9 <Item> 10 <DetailPageURL/> 11 <ItemAttributes> 12 <Author>John Grisham</Author> 13 <Title>A Time to Kill</Title> 14 <Price>12.99</Price> 15 <DatePub>1998-05-01</DatePub> 16 <ASIN>0446351230</ASIN> 17 </ItemAttributes> 18 </Item> 19 <Item> 20 <DetailPageURL/> 21 <ItemAttributes> 22 <Author>Stephen King</Author> 23 <Title>Blood and Smoke</Title> 24 <Price>24.00</Price> 25 <DatePub>2000-01-01</DatePub> 26 <ASIN>0446355453</ASIN> 27 </ItemAttributes> 28 </Item> 29 <Item> 30 <DetailPageURL/> 31 <ItemAttributes> 32 <Author>John Grisham</Author> 33 <Title>The Rainmaker</Title> 34 <Price>7.99</Price> 35 <DatePub>2001-12-01</DatePub> 36 <ASIN>0443622434</ASIN> 37 </ItemAttributes> 38 </Item> 39 <Item> 40 <DetailPageURL/> 41 <ItemAttributes> 42 <Author>Stephen King</Author> 43 <Title>The Green Mile</Title> 44 <Price>24.00</Price> 45 <DatePub>1992-01-01</DatePub> 46 <ASIN>0443622987</ASIN> 47 </ItemAttributes> 48 </Item> 49 <Item> 50 <DetailPageURL/> 51 <ItemAttributes> 52 <Author>Stephen King</Author> 53 <Title>Misery</Title> 54 <Price>7.70</Price> 55 <DatePub>2003-01-01</DatePub> 56 <ASIN>0443623452</ASIN> 57 </ItemAttributes> 58 </Item> 59 <Item> 60 <DetailPageURL/> 61 <ItemAttributes> 62 <Author>Stephen King</Author> 63 <Title>The Dark Half</Title> 64 <Price>48.00</Price> 65 <DatePub>1999-10-30</DatePub> 66 <ASIN>0443623482</ASIN> 67 </ItemAttributes> 68 </Item> 69 <Item> 70 <DetailPageURL/> 71 <ItemAttributes> 72 <Author>John Grisham</Author> 73 <Title>The Partner</Title> 74 <Price>12.99</Price> 75 <DatePub>2005-01-01</DatePub> 76 <ASIN>0443744434</ASIN> 77 </ItemAttributes> 78 </Item> 79 <Item> 80 <DetailPageURL/> 81 <ItemAttributes> 82 <Author>Stephen King</Author> 83 <Title>It</Title> 84 <Price>9.70</Price> 85 <DatePub>2001-10-15</DatePub> 86 <ASIN>0443698452</ASIN> 87 </ItemAttributes> 88 </Item> 89 <Item> 90 <DetailPageURL/> 91 <ItemAttributes> 92 <Author>Honore de Balzac</Author> 93 <Title>Cousin Bette</Title> 94 <Price>19.70</Price> 95 <DatePub>1991-12-01</DatePub> 96 <ASIN>0443691234</ASIN> 97 </ItemAttributes> 98 </Item> 99 <Item> 100 <DetailPageURL/> 101 <ItemAttributes> 102 <Author>Alexandr Pushkin</Author> 103 <Title>Boris Godunov</Title> 104 <Price>7.15</Price> 105 <DatePub>1999-01-01</DatePub> 106 <ASIN>0447791234</ASIN> 107 </ItemAttributes></Item> 108 <Item> 109 <DetailPageURL/> 110 <ItemAttributes> 111 <Author>Alice in Wonderland</Author> 112 <Title>Lewis Carroll</Title> 113 <Price>4.15</Price> 114 <DatePub>1999-01-01</DatePub> 115 <ASIN>0447791294</ASIN> 116 </ItemAttributes> 117 </Item> 118 </Items> 119 </Books>
浙公网安备 33010602011771号