jqgridDatas.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * 返回json格式中 最好默认带有ID列
  3. 默认显示 20列
  4. * 列表id = 'gridTable'
  5. 列表url = 'Handler.ashx?action=page'
  6. 列表datatype = 'json'
  7. 列表colNames = ['ID', '名称', '性别', '手机', '邮箱']
  8. 列表colModel = 。。。
  9. 列表标题 caption = '用户列表'
  10. 列表修改URL editurl = 'Handler.ashx?action=oper'
  11. 列表默认排序 sortname = 'ID';
  12. 页码ID gridPagerID = 'gridPager'
  13. */
  14. //最后选中的行
  15. var lastsel;
  16. function myJqGrid(id, url, datatype, colNames, colModel, caption,
  17. sortname, gridPagerID,sortorder,height,width,
  18. multiselect,rownumbers) {
  19. var myGrid = $('#' + id);
  20. myGrid.jqGrid({
  21. url: url,
  22. datastr: 'data.json',
  23. datatype: datatype,
  24. height:height,
  25. width:width,
  26. rowNum: 5000,
  27. rowList: [10, 20, 50],
  28. colNames: colNames,
  29. colModel: colModel,
  30. jsonReader: {
  31. repeatitems: false,
  32. root: function (obj) { return obj.rows; },
  33. page: function (obj) { return obj.pageindex; },
  34. total: function (obj) { return obj.pagecount; },
  35. records: function (obj) { return obj.total; }
  36. },
  37. prmNames: {
  38. page: 'page',
  39. rows: 'pageSize',
  40. sort: 'sortorder',
  41. order: 'sortname'
  42. },
  43. hidegrid: false,
  44. rownumbers: rownumbers,
  45. multiselect:multiselect,
  46. loadonce: false,
  47. sortname: sortname,
  48. sortorder: sortorder,
  49. viewrecords: true,
  50. caption: caption,
  51. //toolbar: [true, 'top'],
  52. altRows: true,
  53. //最后选中的行
  54. onSelectRow: function (id) {
  55. if (id && id !== lastsel) {
  56. myGrid.jqGrid('restoreRow', lastsel);
  57. lastsel = myGrid.jqGrid('getRowData', id)[sortname];
  58. }
  59. },
  60. onCellSelect: function(rowid, index, contents, event) {
  61. if(rowid!=null && rowid!='null')
  62. {
  63. $("#f1").attr("action","editDatas.action?vo.projectid="+rowid).submit();
  64. }
  65. }
  66. });
  67. }