TableData.cshtml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. @{
  2. ViewBag.Title = "表数据";
  3. Layout = "~/Views/Shared/_Index.cshtml";
  4. }
  5. <script>
  6. var dataBaseLinkId = request('dataBaseLinkId');
  7. var tableName = request('tableName');
  8. $(function () {
  9. InitialPage();
  10. GetGrid();
  11. });
  12. //初始化页面
  13. function InitialPage() {
  14. //resize重设(表格、树形)宽高
  15. $(window).resize(function (e) {
  16. window.setTimeout(function () {
  17. $('#gridTable').setGridWidth(($('.gridPanel').width()));
  18. $("#gridTable").setGridHeight($(window).height() - 140);
  19. }, 200);
  20. e.stopPropagation();
  21. });
  22. }
  23. //加载表格
  24. function GetGrid() {
  25. var colModelData = [];
  26. $.ajax({
  27. url: "../..//SystemManage/DataBaseTable/GetTableFiledListJson",
  28. data: { dataBaseLinkId: dataBaseLinkId, tableName: tableName },
  29. type: "get",
  30. dataType: "json",
  31. async: false,
  32. success: function (json) {
  33. $.each(json, function (i) {
  34. var field = json[i].column.toLocaleLowerCase();;
  35. var remark = json[i].remark;
  36. $("#switchWhere").append($("<option title=" + remark + "></option>").val(field).html(field));
  37. colModelData.push({ label: "<div title=" + remark + ">" + field + "</div>", name: field, align: "left", index: field, editable: true });
  38. });
  39. }
  40. });
  41. var $gridTable = $("#gridTable");
  42. $gridTable.jqGrid({
  43. url: "../../SystemManage/DataBaseTable/GetTableDataListJson",
  44. postData: { dataBaseLinkId: dataBaseLinkId, tableName: tableName },
  45. datatype: "json",
  46. height: $(window).height() - 120,
  47. autowidth: true,
  48. colModel: colModelData,
  49. unwritten: false,
  50. viewrecords: true,
  51. rowNum: 30,
  52. rowList: [30, 50, 100],
  53. pager: "#gridPager",
  54. sortorder: 'desc',
  55. rownumbers: true,
  56. shrinkToFit: false,
  57. gridview: true
  58. });
  59. //查询事件
  60. $("#btn_Search").click(function () {
  61. $gridTable.jqGrid('setGridParam', {
  62. postData: {
  63. dataBaseLinkId: dataBaseLinkId,
  64. tableName: tableName,
  65. switchWhere: $("#switchWhere").val(),
  66. logic: $("#logic").val(),
  67. keyword: $("#txt_Keyword").val()
  68. },
  69. }).trigger('reloadGrid');
  70. });
  71. }
  72. </script>
  73. <div class="titlePanel" style="border: 0px;">
  74. <div class="title-search">
  75. <table>
  76. <tr>
  77. <th style="white-space: nowrap; font-weight: normal;">查询条件:</th>
  78. <td>
  79. <select id="switchWhere" class="form-control" style="width: 100px"></select>
  80. </td>
  81. <td style="padding-left: 1px;">
  82. <select id="logic" class="form-control">
  83. <option value="Equal">等于</option>
  84. <option value="NotEqual">不等于</option>
  85. <option value="Greater">大于</option>
  86. <option value="GreaterThan">大于等于</option>
  87. <option value="Less">小于</option>
  88. <option value="LessThan">小于等于</option>
  89. <option value="Null">为空</option>
  90. <option value="NotNull">不为空</option>
  91. <option value="Like">包含</option>
  92. </select>
  93. </td>
  94. <td style="padding-left: 1px;">
  95. <input id="txt_Keyword" type="text" class="form-control" placeholder="请输入要查询关键字" style="width: 200px;" />
  96. </td>
  97. <td style="padding-left: 5px;">
  98. <a id="btn_Search" class="btn btn-primary"><i class="fa fa-search"></i>&nbsp;查询</a>
  99. </td>
  100. </tr>
  101. </table>
  102. </div>
  103. </div>
  104. <div class="gridPanel">
  105. <table id="gridTable"></table>
  106. <div id="gridPager"></div>
  107. </div>
  108. <style>
  109. body {
  110. margin: 0px;
  111. }
  112. .ui-widget-content {
  113. border-left: 0px;
  114. border-right: 0px;
  115. border-bottom: 0px;
  116. }
  117. </style>