testCountryList.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <%@ page contentType="text/html;charset=UTF-8" %>
  2. <script>
  3. $(document).ready(function() {
  4. $('#testCountryTable').bootstrapTable({
  5. //请求方法
  6. method: 'post',
  7. //类型json
  8. dataType: "json",
  9. contentType: "application/x-www-form-urlencoded",
  10. //显示刷新按钮
  11. showRefresh: true,
  12. //显示切换手机试图按钮
  13. showToggle: true,
  14. //显示 内容列下拉框
  15. showColumns: true,
  16. //显示到处按钮
  17. showExport: true,
  18. //显示切换分页按钮
  19. showPaginationSwitch: true,
  20. //最低显示2行
  21. minimumCountColumns: 2,
  22. //是否显示行间隔色
  23. striped: true,
  24. //是否使用缓存,默认为true,所以一般情况下需要设置一下这个属性(*)
  25. cache: false,
  26. //是否显示分页(*)
  27. pagination: true,
  28. //排序方式
  29. sortOrder: "asc",
  30. //初始化加载第一页,默认第一页
  31. pageNumber:1,
  32. //每页的记录行数(*)
  33. pageSize: 10,
  34. //可供选择的每页的行数(*)
  35. pageList: [10, 25, 50, 100],
  36. //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
  37. url: "${ctx}/test/grid/testCountry/data",
  38. //默认值为 'limit',传给服务端的参数为:limit, offset, search, sort, order Else
  39. //queryParamsType:'',
  40. ////查询参数,每次调用是会带上这个参数,可自定义
  41. queryParams : function(params) {
  42. var searchParam = $("#searchForm").serializeJSON();
  43. searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
  44. searchParam.pageSize = params.limit === undefined? -1 : params.limit;
  45. searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+ params.order;
  46. return searchParam;
  47. },
  48. //分页方式:client客户端分页,server服务端分页(*)
  49. sidePagination: "server",
  50. contextMenuTrigger:"right",//pc端 按右键弹出菜单
  51. contextMenuTriggerMobile:"press",//手机端 弹出菜单,click:单击, press:长按。
  52. contextMenu: '#context-menu',
  53. onContextMenuItem: function(row, $el){
  54. if($el.data("item") == "edit"){
  55. edit(row.id);
  56. } else if($el.data("item") == "delete"){
  57. jp.confirm('确认要删除该国家记录吗?', function(){
  58. jp.loading();
  59. jp.get("${ctx}/test/grid/testCountry/delete?id="+row.id, function(data){
  60. if(data.success){
  61. $('#testCountryTable').bootstrapTable('refresh');
  62. jp.success(data.msg);
  63. }else{
  64. jp.error(data.msg);
  65. }
  66. })
  67. });
  68. }
  69. },
  70. onClickRow: function(row, $el){
  71. },
  72. columns: [{
  73. checkbox: true
  74. }
  75. ,{
  76. field: 'name',
  77. title: '国名',
  78. sortable: true
  79. ,formatter:function(value, row , index){
  80. return "<a href='javascript:edit(\""+row.id+"\")'>"+value+"</a>";
  81. }
  82. }
  83. ,{
  84. field: 'sum',
  85. title: '人口',
  86. sortable: true
  87. }
  88. ,{
  89. field: 'continent.name',
  90. title: '所属洲',
  91. sortable: true
  92. }
  93. ,{
  94. field: 'remarks',
  95. title: '备注信息',
  96. sortable: true
  97. }
  98. ]
  99. });
  100. if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端
  101. $('#testCountryTable').bootstrapTable("toggleView");
  102. }
  103. $('#testCountryTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
  104. 'check-all.bs.table uncheck-all.bs.table', function () {
  105. $('#remove').prop('disabled', ! $('#testCountryTable').bootstrapTable('getSelections').length);
  106. $('#edit').prop('disabled', $('#testCountryTable').bootstrapTable('getSelections').length!=1);
  107. });
  108. $("#btnImport").click(function(){
  109. jp.open({
  110. type: 2,
  111. area: [500, 200],
  112. auto: true,
  113. title:"导入数据",
  114. content: "${ctx}/tag/importExcel" ,
  115. btn: ['下载模板','确定', '关闭'],
  116. btn1: function(index, layero){
  117. jp.downloadFile('${ctx}/test/grid/testCountry/import/template');
  118. },
  119. btn2: function(index, layero){
  120. var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
  121. iframeWin.contentWindow.importExcel('${ctx}/test/grid/testCountry/import', function (data) {
  122. if(data.success){
  123. jp.success(data.msg);
  124. refresh();
  125. }else{
  126. jp.error(data.msg);
  127. }
  128. jp.close(index);
  129. });//调用保存事件
  130. return false;
  131. },
  132. btn3: function(index){
  133. jp.close(index);
  134. }
  135. });
  136. });
  137. $("#export").click(function(){//导出Excel文件
  138. jp.downloadFile('${ctx}/test/grid/testCountry/export');
  139. })
  140. $("#search").click("click", function() {// 绑定查询按扭
  141. $('#testCountryTable').bootstrapTable('refresh');
  142. });
  143. $("#reset").click("click", function() {// 绑定查询按扭
  144. $("#searchForm input").val("");
  145. $("#searchForm select").val("");
  146. $("#searchForm .select-item").html("");
  147. $('#testCountryTable').bootstrapTable('refresh');
  148. });
  149. });
  150. function getIdSelections() {
  151. return $.map($("#testCountryTable").bootstrapTable('getSelections'), function (row) {
  152. return row.id
  153. });
  154. }
  155. function deleteAll(){
  156. jp.confirm('确认要删除该国家记录吗?', function(){
  157. jp.loading();
  158. jp.get("${ctx}/test/grid/testCountry/deleteAll?ids=" + getIdSelections(), function(data){
  159. if(data.success){
  160. $('#testCountryTable').bootstrapTable('refresh');
  161. jp.success(data.msg);
  162. }else{
  163. jp.error(data.msg);
  164. }
  165. })
  166. })
  167. }
  168. function add(){
  169. jp.openSaveDialog('新增国家', "${ctx}/test/grid/testCountry/form",'800px', '500px');
  170. }
  171. function refresh(){
  172. $('#testCountryTable').bootstrapTable('refresh');
  173. }
  174. function edit(id){//没有权限时,不显示确定按钮
  175. if(id == undefined){
  176. id = getIdSelections();
  177. }
  178. <shiro:hasPermission name="test:grid:testCountry:edit">
  179. jp.openSaveDialog('编辑国家', "${ctx}/test/grid/testCountry/form?id=" + id,'800px', '500px');
  180. </shiro:hasPermission>
  181. <shiro:lacksPermission name="test:grid:testCountry:edit">
  182. jp.openViewDialog('查看国家', "${ctx}/test/grid/testCountry/form?id=" + id,'800px', '500px');
  183. </shiro:lacksPermission>
  184. }
  185. </script>