jqGrid 属性、事件全集(三)——实时数据操作

 1 This example show how we can add dialog for live data search.
 2 Description
 3 This method uses colModel names and url parameters from jqGrid
 4 Calling: jQuery("#grid_id").searchGrid( options );
 5 options 
 6 top : 0 the initial top position of search dialog
 7 left: 0 the initinal left position of search dialog
 8 If the left and top positions are not set the dialog apper on
 9 upper left corner of the grid 
10 width: 360, the width of serch dialog - default 360
11 height: 70, the height of serch dialog default 70
12 modal: false, determine if the dialog should be in modal mode default is false
13 drag: true,determine if the dialog is dragable default true
14 caption: "Search...",the caption of the dialog
15 Find: "Find", the text of the button when you click to search data default Find
16 Reset: "Reset",the text of the button when you click to clear search string default Reset
17 dirty: false, applicable only in navigator see the last example
18 These parameters are passed to the url 
19 sField:'searchField', is the name that is passed to url the value is the name from colModel
20 sValue:'searchString',is the name that is passed to url the value is the entered value
21 sOper: 'searchOper', is the name that is passed to the url the value is the type of search - see sopt array
22 // translation string for the search options
23 odata : ['equal', 'not equal', 'less', 'less or equal','greater','greater or equal', 'begins with','ends with','contains' ],
24 // if you want to change or remove the order change it in sopt
25 sopt: null // ['bw','eq','ne','lt','le','gt','ge','ew','cn'] 
26 by default all options are allowed. The codes are as follow:
27 bw - begins with ( LIKE val% )
28 eq - equal ( = )
29 ne - not equal ( <> )
30 lt - little ( < )
31 le - little or equal ( <= )
32 gt - greater ( > )
33 ge - greater or equal ( >= )
34 ew - ends with (LIKE %val )
35 cn - contain (LIKE %val% )
1 <table id="search"></table> 
2 <div id="pagersr"></div> 
3 <input type="BUTTON" id="bsdata" value="Search" />

查询数据

 1 jQuery("#search").jqGrid({ 
 2     url:'server.php?q=1', 
 3     datatype: "xml", 
 4     colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'], 
 5     colModel:[ 
 6         {name:'id',index:'id', width:55}, 
 7         {name:'invdate',index:'invdate', width:90}, 
 8         {name:'name',index:'name', width:100}, 
 9         {name:'amount',index:'amount', width:80, align:"right"}, 
10         {name:'tax',index:'tax', width:80, align:"right"}, 
11         {name:'total',index:'total', width:80,align:"right"}, 
12         {name:'note',index:'note', width:150, sortable:false}
13     ],
14     rowNum:10, 
15     rowList:[10,20,30], 
16     pager: '#pagersr', 
17     sortname: 'id', 
18     viewrecords: true, 
19     sortorder: "desc", 
20     caption:"Search Example", 
21     editurl:"someurl.php" 
22 }); 
$("#bsdata").click(function(){ 
    jQuery("#search").jqGrid('searchGrid', {sopt:['cn','bw','eq','ne','lt','gt','ew']} ); 
});
1 <table id="editgrid"></table> 
2 <div id="pagered"></div> 
3 <input type="BUTTON" id="bedata" value="Edit Selected" />
 1 jQuery("#editgrid").jqGrid({ 
 2     url:'editing.php?q=1', 
 3     datatype: "xml", 
 4     colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Closed','Ship via','Notes'], 
 5     colModel:[ 
 6         {name:'id',index:'id', width:55,editable:false,editoptions:{readonly:true,size:10}}, 
 7         {name:'invdate',index:'invdate', width:80,editable:true,editoptions:{size:10}}, 
 8         {name:'name',index:'name', width:90,editable:true,editoptions:{size:25}}, 
 9         {name:'amount',index:'amount', width:60, align:"right",editable:true,editoptions:{size:10}}, 
10         {name:'tax',index:'tax', width:60, align:"right",editable:true,editoptions:{size:10}}, 
11         {name:'total',index:'total', width:60,align:"right",editable:true,editoptions:{size:10}}, 
12         {name:'closed',index:'closed',width:55,align:'center',editable:true,edittype:"checkbox",editoptions:{value:"Yes:No"}}, 
13         {name:'ship_via',index:'ship_via',width:70, editable: true,edittype:"select",editoptions:{value:"FE:FedEx;TN:TNT"}}, 
14         {name:'note',index:'note', width:100, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"20"}} 
15     ], 
16     rowNum:10, 
17     rowList:[10,20,30], 
18     pager: '#pagered', 
19     sortname: 'id', 
20     viewrecords: true, 
21     sortorder: "desc", 
22     caption:"Editing Example", 
23     editurl:"someurl.php" 
24 }); 
25 //编辑行
26 $("#bedata").click(function(){ 
27     var gr = jQuery("#editgrid").jqGrid('getGridParam','selrow'); 
28 if( gr != null ) 
29     jQuery("#editgrid").jqGrid('editGridRow',gr,{height:280,reloadAfterSubmit:false}); 
30 else 
31     alert("Please Select Row"); 
32 });
33 //添加行
34 $("#bedata").click(function(){ 
35     jQuery("#editgrid").jqGrid('editGridRow',"new",{height:280,reloadAfterSubmit:false}); 
36 });
37 //删除行
38 $("#dedata").click(function(){ 
39 var gr = jQuery("#delgrid").jqGrid('getGridParam','selrow'); 
40 if( gr != null ) 
41     jQuery("#delgrid").jqGrid('delGridRow',gr,{reloadAfterSubmit:false}); 
42 else 
43     alert("Please Select Row to delete!"); 
44 });
45 
46 jQuery("#navgrid").jqGrid(
47     'navGrid',
48     '#pagernav', 
49     {}, //options 
50     {height:280,reloadAfterSubmit:false}, // edit options 
51     {height:280,reloadAfterSubmit:false}, // add options 
52     {reloadAfterSubmit:false}, // del options 
53     {} // search options 
54 );
说明:
编辑行:
Description 
This method uses colModel and editurl parameters from jqGrid
Calling: jQuery("#grid_id").jqGrid('editGridRow', the_row_id, options );
the_row_id is the row to edit 
options 
top : 0 the initial top position of edit dialog
left: 0 the initinal left position of edit dialog
If the left and top positions are not set the dialog apper on
upper left corner of the grid 
width: 0, the width of edit dialog - default 300
height: 0, the height of edit dialog default 200
modal: false, determine if the dialog should be in modal mode default is false
drag: true,determine if the dialog is dragable default true
addCaption: "Add Record",the caption of the dialog if the mode is adding
editCaption: "Edit Record",the caption of the dialog if the mode is editing
bSubmit: "Submit", the text of the button when you click to data default Submit
bCancel: "Cancel",the text of the button when you click to close dialog default Cancel
url: , url where to post data. If set replace the editurl 
processData: "Processing...", Indicator when posting data
closeAfterAdd : false, when add mode closes the dialog after add record - default false
clearAfterAdd : true, when add mode clears the data after adding data - default true
closeAfterEdit : false, when in edit mode closes the dialog after editing - default false
reloadAfterSubmit : true reloads grid data after posting default is true
// Events 
intializeForm: null fires only once when creating the data for editing and adding.
Paramter passed to the event is the id of the constructed form.
beforeInitData: null fires before initialize the form data.
Paramter passed to the event is the id of the constructed form.
beforeShowForm: null fires before showing the form data.
Paramter passed to the event is the id of the constructed form.
afterShowForm: null fires after the form is shown.
Paramter passed to the event is the id of the constructed form.
beforeSubmit: null fires before the data is submitted to the server
Paramter is array of type name:value. When called the event can return array 
where the first parameter can be true or false and the second is the message of the error if any
Example: [false,"The value is not valid"]
afterSubmit: null fires after the data is posted to the server. Typical this
event is used to recieve status form server if the data is posted with success.
Parameters to this event are the returned data from the request and array of the
posted values of type name:value

添加行:
Description 
This method uses colModel and editurl parameters from jqGrid 
Calling: jQuery("#grid_id").editGridRow( the_row_id, options );
the_row_id when in add mode the special value must be set - "new" 
options 
top : 0 the initial top position of edit dialog
left: 0 the initinal left position of edit dialog
If the left and top positions are not set the dialog apper on
upper left corner of the grid 
width: 0, the width of edit dialog - default 300
height: 0, the height of edit dialog default 200
modal: false, determine if the dialog should be in modal mode default is false
drag: true,determine if the dialog is dragable default true
addCaption: "Add Record",the caption of the dialog if the mode is adding
editCaption: "Edit Record",the caption of the dialog if the mode is editing
bSubmit: "Submit", the text of the button when you click to data default Submit
bCancel: "Cancel",the text of the button when you click to close dialog default Cancel
url: , url where to post data. If set replace the editurl 
processData: "Processing...", Indicator when posting data
closeAfterAdd : false, when add mode closes the dialog after add record - default false
clearAfterAdd : true, when add mode clears the data after adding data - default true
closeAfterEdit : false, when in edit mode closes the dialog after editing - default false
reloadAfterSubmit : true reloads grid data after posting default is true 
// Events 
intializeForm: null fires only once when creating the data for editing and adding.
Paramter passed to the event is the id of the constructed form.
beforeInitData: null fires before initialize the form data.
Paramter passed to the event is the id of the constructed form.
beforeShowForm: null fires before showing the form data.
Paramter passed to the event is the id of the constructed form.
afterShowForm: null fires after the form is shown.
Paramter passed to the event is the id of the constructed form.
beforeSubmit: null fires before the data is submitted to the server
Paramter is array of type name:value. When called the event can return array 
where the first parameter can be true or false and the second is the message of the error if any
Example: [false,"The value is not valid"]
afterSubmit: null fires after the data is posted to the server. Typical this 
event is used to recieve status form server if the data is posted with success.
Parameters to this event are the returned data from the request and array of the
posted values of type name:value

删除行:
Description 
This method uses colModel and editurl parameters from jqGrid 
Calling: jQuery("#grid_id").jqGrid('delGridRow', row_id_s,options );
row_id_s is the row to delete. When in multiselect automatially delete the selected rows 
options 
top : 0 the initial top position of edit dialog
left: 0 the initinal left position of edit dialog
If the left and top positions are not set the dialog apper on
upper left corner of the grid 
width: 0, the width of edit dialog - default 300
height: 0, the height of edit dialog default 200
modal: false, determine if the dialog should be in modal mode default is false
drag: true,determine if the dialog is dragable default true
msg: "Delete selected row(s),message to display when deleting the row
caption: "Delete Record",the caption of the dialog
bSubmit: "Submit", the text of the button when you click to data default Submit
bCancel: "Cancel",the text of the button when you click to close dialog default Cancel
url: , url where to post data. If set replace the editurl 
reloadAfterSubmit : true reloads grid data after posting default is true 
// Events 
beforeShowForm: null fires before showing the form data.
Paramter passed to the event is the id of the constructed form.
afterShowForm: null fires after the form is shown.
Paramter passed to the event is the id of the constructed form.
beforeSubmit: null fires before the data is submitted to the server
Paramter is of type id=value1,value2,... When called the event can return array 
where the first parameter can be true or false and the second is the message of the error if any
Example: [false,"The value is not valid"]
afterSubmit: null fires after the data is posted to the server. Typical this 
event is used to recieve status form server if the data is posted with success.
Parameters to this event are the returned data from the request and array of the
posted values of type id=value1,value2


Navigator:
This method uses colModel and editurl parameters from jqGrid 
Calling: jQuery("#grid_id").jqGrid('navGrid',selector,options,pEdit,pAdd,pDel,pSearch );

本文出处:http://blog.csdn.net/a416090287/article/details/8456457

感谢:

Rosanu

posted @ 2013-03-08 15:11  软件小书童  阅读(1087)  评论(0)    收藏  举报